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

Lock orientation button

This commit is contained in:
Arkadiusz Fal 2022-07-11 01:26:35 +02:00
parent 5bfc1a3206
commit fc175be76b
3 changed files with 41 additions and 10 deletions

View File

@ -93,6 +93,10 @@ final class PlayerModel: ObservableObject {
backend.setNeedsNetworkStateUpdates(true) backend.setNeedsNetworkStateUpdates(true)
}} }}
#if os(iOS)
@Published var lockedOrientation: UIInterfaceOrientationMask?
#endif
var accounts: AccountsModel var accounts: AccountsModel
var comments: CommentsModel var comments: CommentsModel
var controls: PlayerControlsModel { didSet { var controls: PlayerControlsModel { didSet {
@ -717,7 +721,7 @@ final class PlayerModel: ObservableObject {
#if os(iOS) #if os(iOS)
if !playingFullScreen { if !playingFullScreen {
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait) Orientation.lockOrientation(.allButUpsideDown)
} }
#endif #endif
} }

View File

@ -207,6 +207,7 @@ struct PlayerControls: View {
#if os(iOS) #if os(iOS)
pipButton pipButton
lockOrientationButton
#endif #endif
Spacer() 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 { var floatingControls: some View {
HStack { HStack {
HStack(spacing: 20) { HStack(spacing: 20) {

View File

@ -112,6 +112,13 @@ struct VideoPlayerView: View {
player?.onPresentPlayer?() player?.onPresentPlayer?()
player?.onPresentPlayer = nil player?.onPresentPlayer = nil
} }
if let orientationMask = player.lockedOrientation {
Orientation.lockOrientation(
orientationMask,
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
)
}
} else { } else {
if Defaults[.lockPortraitWhenBrowsing] { if Defaults[.lockPortraitWhenBrowsing] {
Orientation.lockOrientation(.portrait, andRotateTo: .portrait) Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
@ -333,8 +340,12 @@ struct VideoPlayerView: View {
guard drag > 0 else { return } guard drag > 0 else { return }
if drag > 60, player.playingFullScreen { if drag > 60,
player.playingFullScreen,
!OrientationTracker.shared.currentInterfaceOrientation.isLandscape
{
player.exitFullScreen() player.exitFullScreen()
player.lockedOrientation = nil
} }
viewVerticalOffset = drag viewVerticalOffset = drag
@ -343,13 +354,9 @@ struct VideoPlayerView: View {
guard player.presentingPlayer, guard player.presentingPlayer,
!playerControls.presentingControlsOverlay else { return } !playerControls.presentingControlsOverlay else { return }
if viewVerticalOffset > 100 { if viewVerticalOffset > 100 {
if player.playingFullScreen { player.backend.setNeedsDrawing(false)
viewVerticalOffset = 0 player.hide()
player.exitFullScreen() player.exitFullScreen()
} else {
player.backend.setNeedsDrawing(false)
player.hide()
}
} else { } else {
viewVerticalOffset = 0 viewVerticalOffset = 0
player.backend.setNeedsDrawing(true) player.backend.setNeedsDrawing(true)
@ -467,7 +474,11 @@ struct VideoPlayerView: View {
object: nil, object: nil,
queue: .main queue: .main
) { _ in ) { _ in
guard !Defaults[.honorSystemOrientationLock], player.presentingPlayer, !player.playingInPictureInPicture else { guard !Defaults[.honorSystemOrientationLock],
player.presentingPlayer,
!player.playingInPictureInPicture,
player.lockedOrientation.isNil
else {
return return
} }