mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Lock orientation button
This commit is contained in:
parent
5bfc1a3206
commit
fc175be76b
@ -93,6 +93,10 @@ final class PlayerModel: ObservableObject {
|
||||
backend.setNeedsNetworkStateUpdates(true)
|
||||
}}
|
||||
|
||||
#if os(iOS)
|
||||
@Published var lockedOrientation: UIInterfaceOrientationMask?
|
||||
#endif
|
||||
|
||||
var accounts: AccountsModel
|
||||
var comments: CommentsModel
|
||||
var controls: PlayerControlsModel { didSet {
|
||||
@ -717,7 +721,7 @@ final class PlayerModel: ObservableObject {
|
||||
|
||||
#if os(iOS)
|
||||
if !playingFullScreen {
|
||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
||||
Orientation.lockOrientation(.allButUpsideDown)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -207,6 +207,7 @@ struct PlayerControls: View {
|
||||
|
||||
#if os(iOS)
|
||||
pipButton
|
||||
lockOrientationButton
|
||||
#endif
|
||||
|
||||
Spacer()
|
||||
@ -262,6 +263,21 @@ struct PlayerControls: View {
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
private var lockOrientationButton: some View {
|
||||
button("Lock Rotation", systemImage: player.lockedOrientation.isNil ? "lock.rotation.open" : "lock.rotation", active: !player.lockedOrientation.isNil) {
|
||||
if player.lockedOrientation.isNil {
|
||||
let orientationMask = OrientationTracker.shared.currentInterfaceOrientationMask
|
||||
player.lockedOrientation = orientationMask
|
||||
Orientation.lockOrientation(orientationMask)
|
||||
} else {
|
||||
player.lockedOrientation = nil
|
||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
var floatingControls: some View {
|
||||
HStack {
|
||||
HStack(spacing: 20) {
|
||||
|
@ -112,6 +112,13 @@ struct VideoPlayerView: View {
|
||||
player?.onPresentPlayer?()
|
||||
player?.onPresentPlayer = nil
|
||||
}
|
||||
|
||||
if let orientationMask = player.lockedOrientation {
|
||||
Orientation.lockOrientation(
|
||||
orientationMask,
|
||||
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if Defaults[.lockPortraitWhenBrowsing] {
|
||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||
@ -333,8 +340,12 @@ struct VideoPlayerView: View {
|
||||
|
||||
guard drag > 0 else { return }
|
||||
|
||||
if drag > 60, player.playingFullScreen {
|
||||
if drag > 60,
|
||||
player.playingFullScreen,
|
||||
!OrientationTracker.shared.currentInterfaceOrientation.isLandscape
|
||||
{
|
||||
player.exitFullScreen()
|
||||
player.lockedOrientation = nil
|
||||
}
|
||||
|
||||
viewVerticalOffset = drag
|
||||
@ -343,13 +354,9 @@ struct VideoPlayerView: View {
|
||||
guard player.presentingPlayer,
|
||||
!playerControls.presentingControlsOverlay else { return }
|
||||
if viewVerticalOffset > 100 {
|
||||
if player.playingFullScreen {
|
||||
viewVerticalOffset = 0
|
||||
player.exitFullScreen()
|
||||
} else {
|
||||
player.backend.setNeedsDrawing(false)
|
||||
player.hide()
|
||||
}
|
||||
player.backend.setNeedsDrawing(false)
|
||||
player.hide()
|
||||
player.exitFullScreen()
|
||||
} else {
|
||||
viewVerticalOffset = 0
|
||||
player.backend.setNeedsDrawing(true)
|
||||
@ -467,7 +474,11 @@ struct VideoPlayerView: View {
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { _ in
|
||||
guard !Defaults[.honorSystemOrientationLock], player.presentingPlayer, !player.playingInPictureInPicture else {
|
||||
guard !Defaults[.honorSystemOrientationLock],
|
||||
player.presentingPlayer,
|
||||
!player.playingInPictureInPicture,
|
||||
player.lockedOrientation.isNil
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user