1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30

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,47 +204,20 @@ struct VideoPlayerView: View {
hovering ? playerControls.show() : playerControls.hide() hovering ? playerControls.show() : playerControls.hide()
} }
#if !os(macOS) #if !os(macOS)
.gesture( .gesture(playerDragGesture)
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()
}
}
)
#else #else
.onAppear(perform: { .onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
if !player.currentItem.isNil, hoveringPlayer { if !player.currentItem.isNil, hoveringPlayer {
playerControls.resetTimer() playerControls.resetTimer()
} }
return $0 return $0
} }
}) })
#endif #endif
.background(Color.black) .background(Color.black)
#if !os(tvOS) #if !os(tvOS)
if !fullScreenLayout { if !fullScreenLayout {
@ -343,6 +316,41 @@ struct VideoPlayerView: View {
} }
#if os(iOS) #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 { var controlsTopPadding: Double {
guard fullScreenLayout else { return 0 } guard fullScreenLayout else { return 0 }