diff --git a/ios/Stemify/App/StemifyApp.swift b/ios/Stemify/App/StemifyApp.swift index aa7fc74..603eb88 100644 --- a/ios/Stemify/App/StemifyApp.swift +++ b/ios/Stemify/App/StemifyApp.swift @@ -35,12 +35,22 @@ enum Orientation { nonisolated(unsafe) static var mask: UIInterfaceOrientationMask = .allButUpsideDown /// Folded Duo: portrait only. Unfolded Duo: landscape only. Anything else turns freely. - @MainActor static func lock(_ m: UIInterfaceOrientationMask) { - guard m != mask else { return } + /// 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) { + let changed = m != mask mask = m - for case let scene as UIWindowScene in UIApplication.shared.connectedScenes { - scene.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations() - if m != .allButUpsideDown { scene.requestGeometryUpdate(.iOS(interfaceOrientations: m)) { _ in } } + 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) } + } + } } } } diff --git a/ios/Stemify/UI/Nav.swift b/ios/Stemify/UI/Nav.swift index 80a14f9..13c88d1 100644 --- a/ios/Stemify/UI/Nav.swift +++ b/ios/Stemify/UI/Nav.swift @@ -136,6 +136,9 @@ final class Ui { /// Split (unfolded) goes landscape at once. Portrait waits a moment and checks again, so a /// frame without a hinge reading mid-rotation can't throw an unfolded phone back upright. + /// Back in the foreground: the phone may have been folded or unfolded meanwhile. + func resumed() { lockOrientation() } + private func lockOrientation() { if split { Orientation.lock(.landscape); return } guard folded else { Orientation.lock(.allButUpsideDown); return } diff --git a/ios/Stemify/UI/RootView.swift b/ios/Stemify/UI/RootView.swift index f29a272..820bb1b 100644 --- a/ios/Stemify/UI/RootView.swift +++ b/ios/Stemify/UI/RootView.swift @@ -19,6 +19,7 @@ struct RootView: View { .onGeometryChange(for: CGFloat.self) { $0.safeAreaInsets.trailing } action: { ui.sawInsets(trailing: $0, upright: vSize == .regular) } .background(p.bg.ignoresSafeArea()) .onChange(of: ui.tabs) { _, _ in ui.ensureValidTab() } + .onChange(of: phase) { _, ph in if ph == .active { ui.resumed() } } .fullScreenCover(isPresented: Binding(get: { ui.nowPlayingOpen }, set: { ui.nowPlayingOpen = $0 })) { NowPlayingScreen() .overlayHost(ui.overlays, level: 1) @@ -43,6 +44,7 @@ struct RootView: View { } @Environment(\.verticalSizeClass) private var vSize + @Environment(\.scenePhase) private var phase private enum BarItem: Hashable { case deck, tab(Tab) } diff --git a/ios/Stemify/UI/Screens/NowPlayingScreen.swift b/ios/Stemify/UI/Screens/NowPlayingScreen.swift index e0f9907..ffc876c 100644 --- a/ios/Stemify/UI/Screens/NowPlayingScreen.swift +++ b/ios/Stemify/UI/Screens/NowPlayingScreen.swift @@ -124,11 +124,14 @@ struct NowPlayingScreen: View { // (it only overlaps the sliding preset chips) instead of leaving a quarter of the screen empty. // Upright iPhones have no side insets, so this only changes the Duo. // Folded, the bottom inset is empty space too: run the controls down into it, and the art grows into the room. + // The room under the controls has to be inside this view: padding outside it would keep + // the view off the bottom edge, and then it can't run into the home indicator strip. + .padding(.bottom, folded && !docked ? 6 : 0) .ignoresSafeArea(.container, edges: !docked && vSize == .regular ? (folded ? [.trailing, .bottom] : .trailing) : []) // Measured outside the line above, so it still sees the status column. .onGeometryChange(for: Bool.self) { $0.safeAreaInsets.trailing > 20 } action: { folded = $0 && vSize == .regular } .padding(.top, docked ? 4 : tight ? 14 : 20) - .padding(.bottom, tight ? 4 : folded ? 2 : 8) + .padding(.bottom, folded && !docked ? 0 : tight ? 4 : 8) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(c.bg.ignoresSafeArea()) .overlay(alignment: .top) { diff --git a/ios/project.yml b/ios/project.yml index aca5f10..ae392d2 100644 --- a/ios/project.yml +++ b/ios/project.yml @@ -9,7 +9,7 @@ settings: # iOS needs a plain number for the bundle version; the label is what the app and releases show. MARKETING_VERSION: "0.10.0" VERSION_LABEL: "0.10.0" - CURRENT_PROJECT_VERSION: "44" + CURRENT_PROJECT_VERSION: "45" # Dev builds override these (build-ipa.sh dev) so they install next to the release app. APP_ID: org.cdnutter.stemify APP_NAME: Stemify