Player animation improvements

This commit is contained in:
Arkadiusz Fal 2022-05-29 15:35:02 +02:00
parent dd003db261
commit cbb989e2e1

View File

@ -8,9 +8,9 @@ import SwiftUI
struct VideoPlayerView: View { struct VideoPlayerView: View {
#if os(iOS) #if os(iOS)
static let hiddenPlayerOffset = UIScreen.main.bounds.height + 100 static let hiddenPlayerOffset = max(UIScreen.main.bounds.height, UIScreen.main.bounds.width) + 100
#else #else
static let hiddenPlayerOffset = 0.0 static let hiddenPlayerOffset = 0.0
#endif #endif
static let defaultAspectRatio = 16 / 9.0 static let defaultAspectRatio = 16 / 9.0
@ -93,8 +93,7 @@ struct VideoPlayerView: View {
motionManager?.stopAccelerometerUpdates() motionManager?.stopAccelerometerUpdates()
motionManager = nil motionManager = nil
#else playerOffset = Self.hiddenPlayerOffset
playerOffset = Self.hiddenPlayerOffset
#endif #endif
} }
} }
@ -155,46 +154,47 @@ struct VideoPlayerView: View {
} }
#if !os(macOS) #if !os(macOS)
.gesture( .gesture(
DragGesture(minimumDistance: 0) DragGesture(coordinateSpace: .global)
.onChanged { value in .onChanged { value in
guard !fullScreenLayout else { guard !fullScreenLayout else {
return return // swiftlint:disable:this implicit_return
} }
player.backend.setNeedsDrawing(false) player.backend.setNeedsDrawing(false)
let drag = value.translation.height let drag = value.translation.height
guard drag > 0 else { guard drag > 0 else {
return return // swiftlint:disable:this implicit_return
} }
withAnimation(.easeIn(duration: 0.2)) { withAnimation(.easeInOut(duration: 0.2)) {
playerOffset = drag playerOffset = drag
} }
} }
.onEnded { _ in .onEnded { _ in
if playerOffset > 100 { if playerOffset > 100 {
player.backend.setNeedsDrawing(true) player.backend.setNeedsDrawing(false)
player.hide() player.hide()
} else { } else {
player.show()
playerOffset = 0 playerOffset = 0
player.backend.setNeedsDrawing(true)
player.show()
} }
} }
) )
#else #else
.onAppear(perform: { .onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
if hoveringPlayer { if hoveringPlayer {
playerControls.resetTimer() playerControls.resetTimer()
} }
return $0 return $0
} }
}) })
#endif #endif
.background(Color.black) .background(Color.black)
#if !os(tvOS) #if !os(tvOS)
if !playerControls.playingFullscreen { if !playerControls.playingFullscreen {