iOS: unfolded upright never splits, always turns to landscape; orientation request re-checked until it takes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
566c5f7e8f
commit
5868430f8a
4 files changed
+26
-11
No files matched your search
@@ -37,19 +37,19 @@ enum Orientation {
|
||||
/// Folded Duo: portrait only. Unfolded Duo: landscape only. Anything else turns freely.
|
||||
/// Also re-checks the window when the mask is unchanged: a request made while the app was
|
||||
/// in the background can be refused, which left the folded screen stuck sideways on return.
|
||||
@MainActor static func lock(_ m: UIInterfaceOrientationMask, retry: Int = 2) {
|
||||
@MainActor static func lock(_ m: UIInterfaceOrientationMask, retry: Int = 6) {
|
||||
let changed = m != mask
|
||||
mask = m
|
||||
for case let scene as UIWindowScene in UIApplication.shared.connectedScenes where scene.session.role == .windowApplication {
|
||||
if changed { scene.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations() }
|
||||
let now = UIInterfaceOrientationMask(rawValue: 1 << scene.effectiveGeometry.interfaceOrientation.rawValue)
|
||||
guard m != .allButUpsideDown, !m.contains(now) else { continue }
|
||||
scene.requestGeometryUpdate(.iOS(interfaceOrientations: m)) { _ in
|
||||
guard retry > 0 else { return }
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(for: .milliseconds(300))
|
||||
if mask == m { lock(m, retry: retry - 1) }
|
||||
}
|
||||
scene.requestGeometryUpdate(.iOS(interfaceOrientations: m)) { _ in }
|
||||
// The request can be dropped silently (mid-unfold, just back from the background), so check it took.
|
||||
guard retry > 0 else { continue }
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(for: .milliseconds(500))
|
||||
if mask == m { lock(m, retry: retry - 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user