mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 14:20:32 +05:30
Gestures: swipe up toggles fullscreen
This commit is contained in:
parent
2d7a101ce0
commit
119c663436
@ -8,7 +8,7 @@ extension VideoPlayerView {
|
|||||||
.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(-translation.height, translation.height)
|
||||||
state = translation
|
state = translation
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -18,7 +18,8 @@ extension VideoPlayerView {
|
|||||||
.onChanged { value in
|
.onChanged { value in
|
||||||
guard player.presentingPlayer,
|
guard player.presentingPlayer,
|
||||||
!controlsOverlayModel.presenting,
|
!controlsOverlayModel.presenting,
|
||||||
dragGestureState else { return }
|
dragGestureState,
|
||||||
|
!disableToggleGesture else { return }
|
||||||
|
|
||||||
if player.controls.presentingControls, !player.musicMode {
|
if player.controls.presentingControls, !player.musicMode {
|
||||||
player.controls.presentingControls = false
|
player.controls.presentingControls = false
|
||||||
@ -61,19 +62,22 @@ extension VideoPlayerView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard verticalDrag > 0 else { return }
|
// Toggle fullscreen on upward drag only when not disabled
|
||||||
viewDragOffset = verticalDrag
|
if verticalDrag < -50 {
|
||||||
|
if player.playingFullScreen {
|
||||||
if verticalDrag > 60,
|
player.exitFullScreen(showControls: false)
|
||||||
player.playingFullScreen
|
} else {
|
||||||
{
|
player.enterFullScreen()
|
||||||
player.exitFullScreen(showControls: false)
|
}
|
||||||
#if os(iOS)
|
disableGestureTemporarily()
|
||||||
if Constants.isIPhone {
|
return
|
||||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore downward swipes when in fullscreen
|
||||||
|
guard verticalDrag > 0 && !player.playingFullScreen else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
viewDragOffset = verticalDrag
|
||||||
}
|
}
|
||||||
.onEnded { _ in
|
.onEnded { _ in
|
||||||
onPlayerDragGestureEnded()
|
onPlayerDragGestureEnded()
|
||||||
@ -86,16 +90,6 @@ extension VideoPlayerView {
|
|||||||
player.seek.onSeekGestureEnd()
|
player.seek.onSeekGestureEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
if viewDragOffset > 60,
|
|
||||||
player.playingFullScreen
|
|
||||||
{
|
|
||||||
#if os(iOS)
|
|
||||||
player.lockedOrientation = nil
|
|
||||||
#endif
|
|
||||||
player.exitFullScreen(showControls: false)
|
|
||||||
viewDragOffset = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isVerticalDrag = false
|
isVerticalDrag = false
|
||||||
|
|
||||||
guard player.presentingPlayer,
|
guard player.presentingPlayer,
|
||||||
@ -117,4 +111,12 @@ extension VideoPlayerView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to temporarily disable the toggle gesture after a fullscreen change
|
||||||
|
private func disableGestureTemporarily() {
|
||||||
|
disableToggleGesture = true
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
|
||||||
|
disableToggleGesture = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,18 @@ 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
|
// swiftlint:disable private_swiftui_state
|
||||||
@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
|
||||||
|
// swiftlint:enable private_swiftui_state
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// swiftlint:disable private_swiftui_state
|
||||||
|
@State var disableToggleGesture = false
|
||||||
|
// swiftlint:enable private_swiftui_state
|
||||||
|
|
||||||
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private
|
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
Loading…
Reference in New Issue
Block a user