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,7 +8,7 @@ import SwiftUI
struct VideoPlayerView: View {
#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
static let hiddenPlayerOffset = 0.0
#endif
@ -93,7 +93,6 @@ struct VideoPlayerView: View {
motionManager?.stopAccelerometerUpdates()
motionManager = nil
#else
playerOffset = Self.hiddenPlayerOffset
#endif
}
@ -155,30 +154,31 @@ struct VideoPlayerView: View {
}
#if !os(macOS)
.gesture(
DragGesture(minimumDistance: 0)
DragGesture(coordinateSpace: .global)
.onChanged { value in
guard !fullScreenLayout else {
return
return // swiftlint:disable:this implicit_return
}
player.backend.setNeedsDrawing(false)
let drag = value.translation.height
guard drag > 0 else {
return
return // swiftlint:disable:this implicit_return
}
withAnimation(.easeIn(duration: 0.2)) {
withAnimation(.easeInOut(duration: 0.2)) {
playerOffset = drag
}
}
.onEnded { _ in
if playerOffset > 100 {
player.backend.setNeedsDrawing(true)
player.backend.setNeedsDrawing(false)
player.hide()
} else {
player.show()
playerOffset = 0
player.backend.setNeedsDrawing(true)
player.show()
}
}
)