1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30

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 { 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
@ -93,7 +93,6 @@ struct VideoPlayerView: View {
motionManager?.stopAccelerometerUpdates() motionManager?.stopAccelerometerUpdates()
motionManager = nil motionManager = nil
#else
playerOffset = Self.hiddenPlayerOffset playerOffset = Self.hiddenPlayerOffset
#endif #endif
} }
@ -155,30 +154,31 @@ 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()
} }
} }
) )