Player overlaying other views and swipe gesture (fix #44, #130)

This commit is contained in:
Arkadiusz Fal
2022-05-28 23:41:23 +02:00
parent 687949fbd5
commit 78d7693128
17 changed files with 187 additions and 209 deletions

View File

@@ -178,11 +178,7 @@ extension AppleAVPlayerViewController: AVPlayerViewControllerDelegate {
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if self.navigationModel.presentingChannel {
self.playerModel.playerNavigationLinkActive = true
} else {
self.playerModel.show()
}
self.playerModel.show()
#if os(tvOS)
if self.playerModel.playingInPictureInPicture {
@@ -198,7 +194,6 @@ extension AppleAVPlayerViewController: AVPlayerViewControllerDelegate {
func playerViewControllerWillStartPictureInPicture(_: AVPlayerViewController) {
playerModel.playingInPictureInPicture = true
playerModel.playerNavigationLinkActive = false
}
func playerViewControllerWillStopPictureInPicture(_: AVPlayerViewController) {

View File

@@ -240,7 +240,7 @@ struct PlayerControls: View {
player.hide()
player.closePiP()
var delay = 0.3
var delay = 0.2
#if os(macOS)
delay = 0.0
#endif

View File

@@ -21,7 +21,6 @@ struct VideoDetails: View {
@State private var currentPage = Page.info
@Environment(\.presentationMode) private var presentationMode
@Environment(\.inNavigationView) private var inNavigationView
@Environment(\.navigationStyle) private var navigationStyle
@EnvironmentObject<AccountsModel> private var accounts
@@ -112,7 +111,6 @@ struct VideoDetails: View {
.edgesIgnoringSafeArea(.horizontal)
}
}
.padding(.top, inNavigationView && fullScreen ? 10 : 0)
.onAppear {
if video.isNil && !sidebarQueue {
currentPage = .queue

View File

@@ -37,6 +37,10 @@ struct VideoPlayerView: View {
var mouseLocation: CGPoint { NSEvent.mouseLocation }
#endif
#if !os(macOS)
@State private var playerOffset = UIScreen.main.bounds.height
#endif
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerControlsModel> private var playerControls
@EnvironmentObject<PlayerModel> private var player
@@ -54,10 +58,6 @@ struct VideoPlayerView: View {
content
.onAppear {
playerSize = geometry.size
#if os(iOS)
configureOrientationUpdatesBasedOnAccelerometer()
#endif
}
}
.onChange(of: geometry.size) { size in
@@ -70,22 +70,10 @@ struct VideoPlayerView: View {
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
handleOrientationDidChangeNotification()
}
.onDisappear {
guard !playerControls.playingFullscreen else {
return // swiftlint:disable:this implicit_return
}
if Defaults[.lockPortraitWhenBrowsing] {
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
} else {
Orientation.lockOrientation(.allButUpsideDown)
}
motionManager?.stopAccelerometerUpdates()
motionManager = nil
}
#endif
}
.offset(y: playerOffset)
.animation(.easeIn(duration: 0.2), value: playerOffset)
#endif
}
@@ -138,6 +126,59 @@ struct VideoPlayerView: View {
hoveringPlayer = hovering
hovering ? playerControls.show() : playerControls.hide()
}
#if !os(tvOS)
.onChange(of: player.presentingPlayer) { newValue in
if newValue {
playerOffset = 0
#if os(iOS)
configureOrientationUpdatesBasedOnAccelerometer()
#endif
} else {
#if !os(macOS)
playerOffset = UIScreen.main.bounds.height
#if os(iOS)
if Defaults[.lockPortraitWhenBrowsing] {
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
} else {
Orientation.lockOrientation(.allButUpsideDown)
}
motionManager?.stopAccelerometerUpdates()
motionManager = nil
#endif
#endif
}
}
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { value in
guard !fullScreenLayout else {
return
}
player.backend.setNeedsDrawing(false)
let drag = value.translation.height
guard drag > 0 else {
return
}
withAnimation(.easeIn(duration: 0.2)) {
playerOffset = drag
}
}
.onEnded { _ in
if playerOffset > 100 {
player.backend.setNeedsDrawing(true)
player.hide()
} else {
player.show()
playerOffset = 0
}
}
)
#endif
#if os(macOS)
.onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
@@ -406,7 +447,8 @@ struct VideoPlayerView: View {
} else {
guard abs(acceleration.z) <= 0.74,
player.lockedOrientation.isNil,
enterFullscreenInLandscape
enterFullscreenInLandscape,
!lockLandscapeOnRotation
else {
return
}
@@ -421,6 +463,7 @@ struct VideoPlayerView: View {
}
private func handleOrientationDidChangeNotification() {
playerOffset = playerOffset == 0 ? 0 : UIScreen.main.bounds.height
let newOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
if newOrientation?.isLandscape ?? false,
player.presentingPlayer,