mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Merge pull request #652 from stonerl/seek-gesture
small delay before vertical scrubbing is possible
This commit is contained in:
commit
7c108f18ff
@ -3,19 +3,53 @@ import SwiftUI
|
|||||||
|
|
||||||
extension VideoPlayerView {
|
extension VideoPlayerView {
|
||||||
var playerDragGesture: some Gesture {
|
var playerDragGesture: some Gesture {
|
||||||
DragGesture(minimumDistance: 30, coordinateSpace: .global)
|
let longPressGesture = LongPressGesture(minimumDuration: 0)
|
||||||
#if os(iOS)
|
.updating($isLongPressing) { currentState, gestureState, _ in
|
||||||
|
gestureState = currentState
|
||||||
|
}
|
||||||
|
.onEnded { _ in
|
||||||
|
if startTouchTime == nil {
|
||||||
|
startTouchTime = Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let dragGesture = DragGesture(minimumDistance: 30, coordinateSpace: .global)
|
||||||
.updating($dragGestureOffset) { value, state, _ in
|
.updating($dragGestureOffset) { value, state, _ in
|
||||||
guard isVerticalDrag else { return }
|
guard isVerticalDrag else { return }
|
||||||
var translation = value.translation
|
var translation = value.translation
|
||||||
translation.height = max(0, translation.height)
|
translation.height = max(0, translation.height)
|
||||||
state = translation
|
state = translation
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
.updating($dragGestureState) { _, state, _ in
|
.updating($dragGestureState) { _, state, _ in
|
||||||
state = true
|
state = true
|
||||||
}
|
}
|
||||||
.onChanged { value in
|
.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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
guard player.presentingPlayer,
|
||||||
!controlsOverlayModel.presenting,
|
!controlsOverlayModel.presenting,
|
||||||
dragGestureState else { return }
|
dragGestureState else { return }
|
||||||
@ -64,9 +98,7 @@ extension VideoPlayerView {
|
|||||||
guard verticalDrag > 0 else { return }
|
guard verticalDrag > 0 else { return }
|
||||||
viewDragOffset = verticalDrag
|
viewDragOffset = verticalDrag
|
||||||
|
|
||||||
if verticalDrag > 60,
|
if verticalDrag > 60, player.playingFullScreen {
|
||||||
player.playingFullScreen
|
|
||||||
{
|
|
||||||
player.exitFullScreen(showControls: false)
|
player.exitFullScreen(showControls: false)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if Constants.isIPhone {
|
if Constants.isIPhone {
|
||||||
@ -75,10 +107,6 @@ extension VideoPlayerView {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onEnded { _ in
|
|
||||||
onPlayerDragGestureEnded()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onPlayerDragGestureEnded() {
|
func onPlayerDragGestureEnded() {
|
||||||
if horizontalPlayerGestureEnabled, isHorizontalDrag {
|
if horizontalPlayerGestureEnabled, isHorizontalDrag {
|
||||||
|
@ -47,9 +47,13 @@ struct VideoPlayerView: View {
|
|||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
@GestureState var dragGestureState = false
|
@GestureState var dragGestureState = false
|
||||||
@GestureState var dragGestureOffset = CGSize.zero
|
@GestureState var dragGestureOffset = CGSize.zero
|
||||||
@State var isHorizontalDrag = false // swiftlint:disable:this swiftui_state_private
|
@GestureState var isLongPressing = false
|
||||||
@State var isVerticalDrag = false // swiftlint:disable:this swiftui_state_private
|
// swiftlint:disable swiftui_state_private
|
||||||
@State var viewDragOffset = Self.hiddenOffset // swiftlint:disable:this 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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private
|
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private
|
||||||
|
Loading…
Reference in New Issue
Block a user