From 17aeef9af795d382f831d1334c56801e0e489624 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 5 Jul 2022 19:21:01 +0200 Subject: [PATCH] Close overlay with tap outside --- Fixtures/View+Fixtures.swift | 5 +++-- Shared/Player/PlayerGestures.swift | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Fixtures/View+Fixtures.swift b/Fixtures/View+Fixtures.swift index 5a69bc78..080a8525 100644 --- a/Fixtures/View+Fixtures.swift +++ b/Fixtures/View+Fixtures.swift @@ -43,14 +43,15 @@ struct FixtureEnvironmentObjectsModifier: ViewModifier { private var player: PlayerModel { let player = PlayerModel() - player.currentItem = PlayerQueueItem(Video.fixture) + player.currentItem = PlayerQueueItem(Video(videoID: "", title: "", author: "", length: 0, published: "2 days ago", views: 43434, channel: .init(id: "", name: ""), likes: 2332, dislikes: 30)) player.queue = Video.allFixtures.map { PlayerQueueItem($0) } + player.videoBeingOpened = Video.fixture return player } private var playerControls: PlayerControlsModel { - PlayerControlsModel(presentingControls: true, player: player) + PlayerControlsModel(presentingControls: true, presentingControlsOverlay: true, player: player) } private var subscriptions: SubscriptionsModel { diff --git a/Shared/Player/PlayerGestures.swift b/Shared/Player/PlayerGestures.swift index b6370a58..f7535478 100644 --- a/Shared/Player/PlayerGestures.swift +++ b/Shared/Player/PlayerGestures.swift @@ -10,7 +10,15 @@ struct PlayerGestures: View { .tapRecognizer( tapSensitivity: 0.2, singleTapAction: { - model.toggle() + if model.presentingControlsOverlay { + model.presentingControls = true + model.resetTimer() + withAnimation { + model.presentingControlsOverlay = false + } + } else { + model.toggle() + } }, doubleTapAction: { player.backend.seek(relative: .secondsInDefaultTimescale(-10)) @@ -24,7 +32,15 @@ struct PlayerGestures: View { .tapRecognizer( tapSensitivity: 0.2, singleTapAction: { - model.toggle() + if model.presentingControlsOverlay { + model.presentingControls = true + model.resetTimer() + withAnimation { + model.presentingControlsOverlay = false + } + } else { + model.toggle() + } }, doubleTapAction: { player.backend.togglePlay() @@ -38,7 +54,15 @@ struct PlayerGestures: View { .tapRecognizer( tapSensitivity: 0.2, singleTapAction: { - model.toggle() + if model.presentingControlsOverlay { + model.presentingControls = true + model.resetTimer() + withAnimation { + model.presentingControlsOverlay = false + } + } else { + model.toggle() + } }, doubleTapAction: { player.backend.seek(relative: .secondsInDefaultTimescale(10))