Lock screen rotation for the camera (#2353)

This commit is contained in:
Mauro
2024-01-18 14:24:15 +01:00
committed by GitHub
parent 65e9c3baab
commit 3ae33f1309
19 changed files with 180 additions and 53 deletions
@@ -0,0 +1,27 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import UIKit
// sourcery: AutoMockable
protocol OrientationManagerProtocol {
/// Forces the current orientation for the main window, works only on iOS
func setOrientation(_ orientation: UIInterfaceOrientationMask)
/// Locks the current orientation for the main window, works only on iOS
func lockOrientation(_ orientation: UIInterfaceOrientationMask)
}
@@ -18,12 +18,14 @@ import Combine
import SwiftUI
class WindowManager: WindowManagerProtocol {
private let appDelegate: AppDelegate
weak var windowScene: UIWindowScene?
weak var delegate: WindowManagerDelegate?
private(set) var mainWindow: UIWindow!
private(set) var overlayWindow: UIWindow!
private(set) var alternateWindow: UIWindow!
var windows: [UIWindow] {
[mainWindow, overlayWindow, alternateWindow]
}
@@ -34,7 +36,12 @@ class WindowManager: WindowManagerProtocol {
/// A duration that allows window switching to wait a couple of frames to avoid a transition through black.
private let windowHideDelay = Duration.milliseconds(33)
init(appDelegate: AppDelegate) {
self.appDelegate = appDelegate
}
func configure(with windowScene: UIWindowScene) {
self.windowScene = windowScene
mainWindow = windowScene.keyWindow
mainWindow.tintColor = .compound.textActionPrimary
@@ -80,6 +87,14 @@ class WindowManager: WindowManagerProtocol {
mainWindow.isHidden = true
}
}
func setOrientation(_ orientation: UIInterfaceOrientationMask) {
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
}
func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
appDelegate.orientationLock = orientation
}
}
private class PassthroughWindow: UIWindow {
@@ -25,7 +25,7 @@ protocol WindowManagerDelegate: AnyObject {
/// A window manager that supports switching between a main app window with an overlay and
/// an alternate window to switch contexts whilst also preserving the main view hierarchy.
/// Heavily inspired by https://www.fivestars.blog/articles/swiftui-windows/
protocol WindowManagerProtocol: AnyObject {
protocol WindowManagerProtocol: AnyObject, OrientationManagerProtocol {
var delegate: WindowManagerDelegate? { get set }
/// The app's main window (we only support a single scene).