Merge pull request #780 from stonerl/add-overlay-to-video-context-menu

don’t open video when dismissing context menu
This commit is contained in:
Arkadiusz Fal 2024-09-04 09:15:03 +02:00 committed by GitHub
commit 3752f67630
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {
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
}
}
}
}