Update player gesture

This commit is contained in:
Arkadiusz Fal 2022-07-10 15:37:07 +02:00
parent 2cb849ad8e
commit db46289813

View File

@ -204,34 +204,7 @@ struct VideoPlayerView: View {
hovering ? playerControls.show() : playerControls.hide()
}
#if !os(macOS)
.gesture(
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
guard player.presentingPlayer,
!playerControls.presentingControlsOverlay else { return }
let drag = value.translation.height
guard drag > 0 else { return }
viewVerticalOffset = drag
}
.onEnded { _ in
if viewVerticalOffset > 100 {
if player.playingFullScreen {
viewVerticalOffset = 0
player.exitFullScreen()
} else {
player.backend.setNeedsDrawing(false)
player.hide()
}
} else {
viewVerticalOffset = 0
player.backend.setNeedsDrawing(true)
player.show()
}
}
)
.gesture(playerDragGesture)
#else
.onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
@ -343,6 +316,41 @@ struct VideoPlayerView: View {
}
#if os(iOS)
var playerDragGesture: some Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
guard player.presentingPlayer,
!playerControls.presentingControlsOverlay else { return }
let drag = value.translation.height
guard drag > 0 else { return }
if drag > 60, player.playingFullScreen {
player.exitFullScreen()
}
viewVerticalOffset = drag
}
.onEnded { _ in
guard player.presentingPlayer,
!playerControls.presentingControlsOverlay else { return }
if viewVerticalOffset > 100 {
if player.playingFullScreen {
viewVerticalOffset = 0
player.exitFullScreen()
} else {
player.backend.setNeedsDrawing(false)
player.hide()
}
} else {
viewVerticalOffset = 0
player.backend.setNeedsDrawing(true)
player.show()
}
}
}
var controlsTopPadding: Double {
guard fullScreenLayout else { return 0 }