From b00b733fd5ffefe8d1fc5d3f569f55868f71b3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Sun, 1 Sep 2024 11:47:32 +0200 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20open=20video=20when=20dismissin?= =?UTF-8?q?g=20context=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #510 fix tvOS build Signed-off-by: Toni Förster --- Shared/Views/VideoContextMenuView.swift | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Shared/Views/VideoContextMenuView.swift b/Shared/Views/VideoContextMenuView.swift index 45606e49..83a3408b 100644 --- a/Shared/Views/VideoContextMenuView.swift +++ b/Shared/Views/VideoContextMenuView.swift @@ -24,14 +24,42 @@ struct VideoContextMenuView: View { private var backgroundContext = PersistenceController.shared.container.newBackgroundContext() + @State private var isOverlayVisible = false + init(video: Video) { self.video = video _watchRequest = video.watchFetchRequest } var body: some View { - if video.videoID != Video.fixtureID { - contextMenu + ZStack { + // Conditional overlay to block taps on underlying views + if isOverlayVisible { + Color.clear + .contentShape(Rectangle()) + #if !os(tvOS) + // This is not available on tvOS < 16 so we leave out. + // TODO: remove #if when setting the minimum deployment target to >= 16 + .onTapGesture { + // Dismiss overlay without triggering other interactions + isOverlayVisible = false + } + #endif + .ignoresSafeArea() // Ensure overlay covers the entire screen + .accessibilityLabel("Dismiss context menu") + .accessibilityHint("Tap to close the context") + .accessibilityAddTraits(.isButton) + } + + if video.videoID != Video.fixtureID { + contextMenu + .onAppear { + isOverlayVisible = true + } + .onDisappear { + isOverlayVisible = false + } + } } }