mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Merge pull request #669 from yattee/revert-652-seek-gesture
Revert "small delay before vertical scrubbing is possible"
This commit is contained in:
commit
4b21cd48e3
@ -3,109 +3,81 @@ import SwiftUI
|
|||||||
|
|
||||||
extension VideoPlayerView {
|
extension VideoPlayerView {
|
||||||
var playerDragGesture: some Gesture {
|
var playerDragGesture: some Gesture {
|
||||||
let longPressGesture = LongPressGesture(minimumDuration: 0)
|
DragGesture(minimumDistance: 30, coordinateSpace: .global)
|
||||||
.updating($isLongPressing) { currentState, gestureState, _ in
|
#if os(iOS)
|
||||||
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) {
|
guard player.presentingPlayer,
|
||||||
processDragGesture(value)
|
!controlsOverlayModel.presenting,
|
||||||
} else if getElapsedTouchTime() >= 0.25 {
|
dragGestureState else { return }
|
||||||
processDragGesture(value)
|
|
||||||
}
|
if player.controls.presentingControls, !player.musicMode {
|
||||||
}
|
player.controls.presentingControls = false
|
||||||
.onEnded { value in
|
|
||||||
if abs(value.translation.width) < abs(value.translation.height) {
|
|
||||||
onPlayerDragGestureEnded()
|
|
||||||
} else if getElapsedTouchTime() >= 0.25 {
|
|
||||||
onPlayerDragGestureEnded()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startTouchTime = nil
|
if player.musicMode {
|
||||||
}
|
player.backend.stopControlsUpdates()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
let timeSeek = (time / player.playerSize.width) * horizontalDrag * seekGestureSpeed
|
|
||||||
|
|
||||||
player.seek.gestureSeek = timeSeek
|
let verticalDrag = value.translation.height
|
||||||
}
|
let horizontalDrag = value.translation.width
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard verticalDrag > 0 else { return }
|
#if os(iOS)
|
||||||
viewDragOffset = verticalDrag
|
if viewDragOffset > 0, !isVerticalDrag {
|
||||||
|
isVerticalDrag = true
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if verticalDrag > 60, player.playingFullScreen {
|
if !isVerticalDrag,
|
||||||
player.exitFullScreen(showControls: false)
|
horizontalPlayerGestureEnabled,
|
||||||
#if os(iOS)
|
abs(horizontalDrag) > seekGestureSensitivity,
|
||||||
if Constants.isIPhone {
|
!isHorizontalDrag,
|
||||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
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() {
|
func onPlayerDragGestureEnded() {
|
||||||
|
@ -47,13 +47,9 @@ 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
|
||||||
@GestureState var isLongPressing = false
|
@State var isHorizontalDrag = false // swiftlint:disable:this swiftui_state_private
|
||||||
// swiftlint:disable swiftui_state_private
|
@State var isVerticalDrag = false // swiftlint:disable:this swiftui_state_private
|
||||||
@State var isHorizontalDrag = false
|
@State var viewDragOffset = Self.hiddenOffset // swiftlint:disable:this swiftui_state_private
|
||||||
@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