From 28d9554bb1a7ba55a5e69eca6ddc3668e856ee3b Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 25 Jun 2022 18:33:35 +0200 Subject: [PATCH] Fix toggling full screen details --- Shared/Player/PlayerQueueRow.swift | 12 ++++----- Shared/Player/PlayerQueueView.swift | 13 ++++++---- Shared/Player/VideoDetails.swift | 10 +++++--- Shared/Player/VideoPlayerView.swift | 31 ++++++++++++------------ Shared/Views/BrowserPlayerControls.swift | 2 +- Shared/Views/ControlsBar.swift | 15 +++++++++++- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/Shared/Player/PlayerQueueRow.swift b/Shared/Player/PlayerQueueRow.swift index 2e553b76..a8cb1a6f 100644 --- a/Shared/Player/PlayerQueueRow.swift +++ b/Shared/Player/PlayerQueueRow.swift @@ -6,7 +6,7 @@ import SwiftUI struct PlayerQueueRow: View { let item: PlayerQueueItem var history = false - var fullScreen: Bool + @Binding var fullScreen: Bool @EnvironmentObject private var player @@ -14,10 +14,10 @@ struct PlayerQueueRow: View { @FetchRequest private var watchRequest: FetchedResults - init(item: PlayerQueueItem, history: Bool = false, fullScreen: Bool = false) { + init(item: PlayerQueueItem, history: Bool = false, fullScreen: Binding = .constant(false)) { self.item = item self.history = history - self.fullScreen = fullScreen + _fullScreen = fullScreen _watchRequest = FetchRequest( entity: Watch.entity(), sortDescriptors: [], @@ -41,9 +41,9 @@ struct PlayerQueueRow: View { } if fullScreen { -// withAnimation { -// fullScreen = false -// } + withAnimation { + fullScreen = false + } } if closePiPOnNavigation, player.playingInPictureInPicture { diff --git a/Shared/Player/PlayerQueueView.swift b/Shared/Player/PlayerQueueView.swift index 04c536c2..f6d086d1 100644 --- a/Shared/Player/PlayerQueueView.swift +++ b/Shared/Player/PlayerQueueView.swift @@ -4,7 +4,7 @@ import SwiftUI struct PlayerQueueView: View { var sidebarQueue: Bool - var fullScreen: Bool + @Binding var fullScreen: Bool @FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)]) var watches: FetchedResults @@ -49,7 +49,10 @@ struct PlayerQueueView: View { } ForEach(player.queue) { item in - PlayerQueueRow(item: item, fullScreen: fullScreen) + PlayerQueueRow(item: item, fullScreen: $fullScreen) + .onAppear { + player.loadQueueVideoDetails(item) + } .contextMenu { removeButton(item) removeAllButton() @@ -70,7 +73,7 @@ struct PlayerQueueView: View { PlayerQueueRow( item: PlayerQueueItem.from(watch, video: player.historyVideo(watch.videoID)), history: true, - fullScreen: fullScreen + fullScreen: $fullScreen ) .onAppear { player.loadHistoryVideoDetails(watch.videoID) @@ -89,7 +92,7 @@ struct PlayerQueueView: View { if !player.currentVideo.isNil, !player.currentVideo!.related.isEmpty { Section(header: Text("Related")) { ForEach(player.currentVideo!.related) { video in - PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: fullScreen) + PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: $fullScreen) .contextMenu { Button { player.playNext(video) @@ -137,7 +140,7 @@ struct PlayerQueueView: View { struct PlayerQueueView_Previews: PreviewProvider { static var previews: some View { VStack { - PlayerQueueView(sidebarQueue: true, fullScreen: true) + PlayerQueueView(sidebarQueue: true, fullScreen: .constant(true)) } .injectFixtureEnvironmentObjects() } diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index 38c713cc..069120a7 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -25,7 +25,7 @@ struct VideoDetails: View { } var sidebarQueue: Bool - var fullScreen: Bool + @Binding var fullScreen: Bool @State private var subscribed = false @State private var subscriptionToggleButtonDisabled = false @@ -58,7 +58,9 @@ struct VideoDetails: View { presentingControls: false, backgroundEnabled: false, borderTop: false, - detailsTogglePlayer: false + detailsTogglePlayer: false, + detailsToggleFullScreen: true, + fullScreen: $fullScreen ) HStack(spacing: 4) { @@ -175,7 +177,7 @@ struct VideoDetails: View { .edgesIgnoringSafeArea(.horizontal) case .queue: - PlayerQueueView(sidebarQueue: sidebarQueue, fullScreen: fullScreen) + PlayerQueueView(sidebarQueue: sidebarQueue, fullScreen: $fullScreen) .edgesIgnoringSafeArea(.horizontal) case .related: @@ -325,7 +327,7 @@ struct VideoDetails: View { struct VideoDetails_Previews: PreviewProvider { static var previews: some View { - VideoDetails(sidebarQueue: true, fullScreen: false) + VideoDetails(sidebarQueue: true, fullScreen: .constant(false)) .injectFixtureEnvironmentObjects() } } diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 1cc0b651..0104a90d 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -50,6 +50,7 @@ struct VideoPlayerView: View { @EnvironmentObject private var accounts @EnvironmentObject private var navigation @EnvironmentObject private var player + @EnvironmentObject private var playerControls @EnvironmentObject private var recents @EnvironmentObject private var search @EnvironmentObject private var thumbnails @@ -179,7 +180,7 @@ struct VideoPlayerView: View { .frame(maxWidth: fullScreenLayout ? .infinity : nil, maxHeight: fullScreenLayout ? .infinity : nil) .onHover { hovering in hoveringPlayer = hovering -// hovering ? playerControls.show() : playerControls.hide() + hovering ? playerControls.show() : playerControls.hide() } #if !os(macOS) .gesture( @@ -210,30 +211,30 @@ struct VideoPlayerView: View { } ) #else -// .onAppear(perform: { -// NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { -// if hoveringPlayer { -// playerControls.resetTimer() -// } -// -// return $0 -// } -// }) + .onAppear(perform: { + NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { + if hoveringPlayer { + playerControls.resetTimer() + } + + return $0 + } + }) #endif -.background(Color.black) + .background(Color.black) #if !os(tvOS) if !player.playingFullScreen { VStack(spacing: 0) { #if os(iOS) if verticalSizeClass == .regular { - VideoDetails(sidebarQueue: sidebarQueue, fullScreen: fullScreenDetails) + VideoDetails(sidebarQueue: sidebarQueue, fullScreen: $fullScreenDetails) .edgesIgnoringSafeArea(.bottom) } #else - VideoDetails(sidebarQueue: sidebarQueue, fullScreen: fullScreenDetails) + VideoDetails(sidebarQueue: sidebarQueue, fullScreen: $fullScreenDetails) #endif } @@ -255,12 +256,12 @@ struct VideoPlayerView: View { if !player.playingFullScreen { #if os(iOS) if sidebarQueue { - PlayerQueueView(sidebarQueue: true, fullScreen: fullScreenDetails) + PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails) .frame(maxWidth: 350) } #elseif os(macOS) if Defaults[.playerSidebar] != .never { - PlayerQueueView(sidebarQueue: true, fullScreen: fullScreenDetails) + PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails) .frame(minWidth: 300) } #endif diff --git a/Shared/Views/BrowserPlayerControls.swift b/Shared/Views/BrowserPlayerControls.swift index d0f2855e..83227c5f 100644 --- a/Shared/Views/BrowserPlayerControls.swift +++ b/Shared/Views/BrowserPlayerControls.swift @@ -42,7 +42,7 @@ struct BrowserPlayerControls: View { toolbar .borderTop(height: 0.4, color: Color("ControlsBorderColor")) .modifier(ControlBackgroundModifier()) - ControlsBar() + ControlsBar(fullScreen: .constant(false)) .edgesIgnoringSafeArea(.bottom) } #endif diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index 607a850b..59397a1a 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -19,6 +19,9 @@ struct ControlsBar: View { var borderTop = true var borderBottom = true var detailsTogglePlayer = true + var detailsToggleFullScreen = false + + @Binding var fullScreen: Bool var body: some View { HStack(spacing: 0) { @@ -55,6 +58,16 @@ struct ControlsBar: View { details .contentShape(Rectangle()) } + } else if detailsToggleFullScreen { + Button { + withAnimation { + fullScreen.toggle() + } + } label: { + details + .contentShape(Rectangle()) + } + .keyboardShortcut("t") } else { details } @@ -250,7 +263,7 @@ struct ControlsBar: View { struct ControlsBar_Previews: PreviewProvider { static var previews: some View { - ControlsBar() + ControlsBar(fullScreen: .constant(false)) .injectFixtureEnvironmentObjects() } }