From 2e48016dbbab8c894e72bdeda32e562b4601c1b5 Mon Sep 17 00:00:00 2001 From: "xuan.huang" <5563315+Huxpro@users.noreply.github.com> Date: Sun, 9 Aug 2026 13:55:06 +0800 Subject: [PATCH] [BugFix][iOS] Avoid host orientation recursion - Read orientation from the navigation stack top controller for every host type. - Fall back to the Sparkling controller base policy when the stack has no top controller. - Cover a non-Sparkling host controller to prevent delegate recursion. TEST: SparklingGoTests passed 337 tests in 20 suites on iOS Simulator. Co-authored-by: TRAE CLI --- .../Application/SPKRouterTests.swift | 27 +++++++++++++++++++ .../Container/SPKViewController.swift | 8 +++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/playground/ios/SparklingGoTests/Application/SPKRouterTests.swift b/packages/playground/ios/SparklingGoTests/Application/SPKRouterTests.swift index 5777209e..8d6ad6e6 100644 --- a/packages/playground/ios/SparklingGoTests/Application/SPKRouterTests.swift +++ b/packages/playground/ios/SparklingGoTests/Application/SPKRouterTests.swift @@ -115,6 +115,33 @@ struct SPKRouterTests { } } + @Test func navigationControllerUsesNonSparklingTopControllerPolicy() { + final class HostViewController: UIViewController { + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + .portraitUpsideDown + } + + override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { + .portraitUpsideDown + } + } + + let delegate = SPKViewController( + withURL: nil, + config: SPKSchemeParam(), + context: SPKContext(), + frame: .zero) + let host = HostViewController() + let navigationController = UINavigationController(rootViewController: host) + + #expect( + delegate.navigationControllerSupportedInterfaceOrientations( + navigationController) == .portraitUpsideDown) + #expect( + delegate.navigationControllerPreferredInterfaceOrientationForPresentation( + navigationController) == .portraitUpsideDown) + } + @Test func viewAppearanceSchedulesPortraitGeometryUpdate() { let context = SPKContext() context.interfaceOrientationPolicy = .portrait diff --git a/packages/sparkling-sdk/ios/Sparkling/Sources/Application/Container/SPKViewController.swift b/packages/sparkling-sdk/ios/Sparkling/Sources/Application/Container/SPKViewController.swift index 1e968f2f..deacfd0b 100644 --- a/packages/sparkling-sdk/ios/Sparkling/Sources/Application/Container/SPKViewController.swift +++ b/packages/sparkling-sdk/ios/Sparkling/Sources/Application/Container/SPKViewController.swift @@ -1121,16 +1121,16 @@ extension SPKViewController: UINavigationControllerDelegate { public func navigationControllerSupportedInterfaceOrientations( _ navigationController: UINavigationController ) -> UIInterfaceOrientationMask { - return (navigationController.topViewController as? SPKViewController)? - .supportedInterfaceOrientations ?? navigationController.supportedInterfaceOrientations + return navigationController.topViewController?.supportedInterfaceOrientations + ?? super.supportedInterfaceOrientations } public func navigationControllerPreferredInterfaceOrientationForPresentation( _ navigationController: UINavigationController ) -> UIInterfaceOrientation { - return (navigationController.topViewController as? SPKViewController)? + return navigationController.topViewController? .preferredInterfaceOrientationForPresentation - ?? navigationController.preferredInterfaceOrientationForPresentation + ?? super.preferredInterfaceOrientationForPresentation } }