Revert "small delay before vertical scrubbing is possible"

This commit is contained in:
Arkadiusz Fal 2024-05-16 18:59:54 +02:00 committed by GitHub
parent db2417e455
commit d67e375f16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 93 deletions

View File

@ -3,109 +3,81 @@ import SwiftUI
extension VideoPlayerView {
var playerDragGesture: some Gesture {
let longPressGesture = LongPressGesture(minimumDuration: 0)
.updating($isLongPressing) { currentState, gestureState, _ in
gestureState = currentState
}
.onEnded { _ in
if startTouchTime == nil {
startTouchTime = Date()
}
}
let dragGesture = DragGesture(minimumDistance: 30, coordinateSpace: .global)
DragGesture(minimumDistance: 30, coordinateSpace: .global)
#if os(iOS)
.updating($dragGestureOffset) { value, state, _ in
guard isVerticalDrag else { return }
var translation = value.translation
translation.height = max(0, translation.height)
state = translation
}
#endif
.updating($dragGestureState) { _, state, _ in
state = true
}
.onChanged { value in
if abs(value.translation.width) < abs(value.translation.height) {
processDragGesture(value)
} else if getElapsedTouchTime() >= 0.25 {
processDragGesture(value)
}
}
.onEnded { value in
if abs(value.translation.width) < abs(value.translation.height) {
onPlayerDragGestureEnded()
} else if getElapsedTouchTime() >= 0.25 {
onPlayerDragGestureEnded()
guard player.presentingPlayer,
!controlsOverlayModel.presenting,
dragGestureState else { return }
if player.controls.presentingControls, !player.musicMode {
player.controls.presentingControls = false
}
startTouchTime = nil
}
return longPressGesture.sequenced(before: dragGesture)
}
func getElapsedTouchTime() -> TimeInterval {
guard let startTouchTime = startTouchTime else {
return 0
}
return Date().timeIntervalSince(startTouchTime)
}
func processDragGesture(_ value: DragGesture.Value) {
guard player.presentingPlayer,
!controlsOverlayModel.presenting,
dragGestureState else { return }
if player.controls.presentingControls, !player.musicMode {
player.controls.presentingControls = false
}
if player.musicMode {
player.backend.stopControlsUpdates()
}
let verticalDrag = value.translation.height
let horizontalDrag = value.translation.width
#if os(iOS)
if viewDragOffset > 0, !isVerticalDrag {
isVerticalDrag = true
}
#endif
if !isVerticalDrag,
horizontalPlayerGestureEnabled,
abs(horizontalDrag) > seekGestureSensitivity,
!isHorizontalDrag,
player.activeBackend == .mpv || !avPlayerUsesSystemControls
{
isHorizontalDrag = true
player.seek.onSeekGestureStart()
viewDragOffset = 0
}
if horizontalPlayerGestureEnabled, isHorizontalDrag {
player.seek.updateCurrentTime {
let time = player.backend.playerItemDuration?.seconds ?? 0
if player.seek.gestureStart.isNil {
player.seek.gestureStart = time
if player.musicMode {
player.backend.stopControlsUpdates()
}
let timeSeek = (time / player.playerSize.width) * horizontalDrag * seekGestureSpeed
player.seek.gestureSeek = timeSeek
}
return
}
let verticalDrag = value.translation.height
let horizontalDrag = value.translation.width
guard verticalDrag > 0 else { return }
viewDragOffset = verticalDrag
#if os(iOS)
if viewDragOffset > 0, !isVerticalDrag {
isVerticalDrag = true
}
#endif
if verticalDrag > 60, player.playingFullScreen {
player.exitFullScreen(showControls: false)
#if os(iOS)
if Constants.isIPhone {
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
if !isVerticalDrag,
horizontalPlayerGestureEnabled,
abs(horizontalDrag) > seekGestureSensitivity,
!isHorizontalDrag,
player.activeBackend == .mpv || !avPlayerUsesSystemControls
{
isHorizontalDrag = true
player.seek.onSeekGestureStart()
viewDragOffset = 0
}
#endif
}
if horizontalPlayerGestureEnabled, isHorizontalDrag {
player.seek.updateCurrentTime {
let time = player.backend.playerItemDuration?.seconds ?? 0
if player.seek.gestureStart.isNil {
player.seek.gestureStart = time
}
let timeSeek = (time / player.playerSize.width) * horizontalDrag * seekGestureSpeed
player.seek.gestureSeek = timeSeek
}
return
}
guard verticalDrag > 0 else { return }
viewDragOffset = verticalDrag
if verticalDrag > 60,
player.playingFullScreen
{
player.exitFullScreen(showControls: false)
#if os(iOS)
if Constants.isIPhone {
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
}
#endif
}
}
.onEnded { _ in
onPlayerDragGestureEnded()
}
}
func onPlayerDragGestureEnded() {

View File

@ -47,13 +47,9 @@ struct VideoPlayerView: View {
#if !os(tvOS)
@GestureState var dragGestureState = false
@GestureState var dragGestureOffset = CGSize.zero
@GestureState var isLongPressing = false
// swiftlint:disable swiftui_state_private
@State var isHorizontalDrag = false
@State var isVerticalDrag = false
@State var viewDragOffset = Self.hiddenOffset
@State var startTouchTime: Date? = nil
// swiftlint:enable swiftui_state_private
@State var isHorizontalDrag = false // swiftlint:disable:this swiftui_state_private
@State var isVerticalDrag = false // swiftlint:disable:this swiftui_state_private
@State var viewDragOffset = Self.hiddenOffset // swiftlint:disable:this swiftui_state_private
#endif
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private