mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Lock screen rotation for the camera (#2353)
This commit is contained in:
@@ -57,13 +57,14 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
||||
private var clientProxyObserver: AnyCancellable?
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
let windowManager: WindowManagerProtocol = WindowManager()
|
||||
let windowManager: WindowManagerProtocol
|
||||
let notificationManager: NotificationManagerProtocol
|
||||
|
||||
private let appRouteURLParser: AppRouteURLParser
|
||||
@Consumable private var storedAppRoute: AppRoute?
|
||||
|
||||
init(appDelegate: AppDelegate) {
|
||||
windowManager = WindowManager(appDelegate: appDelegate)
|
||||
Self.setupEnvironmentVariables()
|
||||
|
||||
let appSettings = AppSettings()
|
||||
|
||||
@@ -22,8 +22,9 @@ enum AppDelegateCallback {
|
||||
case failedToRegisteredNotifications(error: Error)
|
||||
}
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
final class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
let callbacks = PassthroughSubject<AppDelegateCallback, Never>()
|
||||
var orientationLock = UIInterfaceOrientationMask.all
|
||||
|
||||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
|
||||
// Add a SceneDelegate to the SwiftUI scene so that we can connect up the WindowManager.
|
||||
@@ -44,4 +45,8 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
||||
callbacks.send(.failedToRegisteredNotifications(error: error))
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
|
||||
orientationLock
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ struct Application: App {
|
||||
|
||||
init() {
|
||||
if ProcessInfo.isRunningUITests {
|
||||
appCoordinator = UITestsAppCoordinator()
|
||||
appCoordinator = UITestsAppCoordinator(appDelegate: appDelegate)
|
||||
} else if ProcessInfo.isRunningUnitTests {
|
||||
appCoordinator = UnitTestsAppCoordinator()
|
||||
appCoordinator = UnitTestsAppCoordinator(appDelegate: appDelegate)
|
||||
} else {
|
||||
appCoordinator = AppCoordinator(appDelegate: appDelegate)
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user