feat: Implement UIScene lifecycle for iOS#54763
Conversation
|
|
We have an RFC in draft to fix this properly and holistically. Please bear with us while we refine it and we move that forward. |
|
@cipolleschi Thank you for the feedback. Based on your comment above (#issuecomment-3626363532), it sounds like this PR might be superseded by the upcoming RFC that aims to address the UIScene lifecycle more holistically and potentially remove RCTAppDelegate. Should this PR be closed for now to await the RFC, or are there parts that could be adapted later? |
|
Hi @cipolleschi, thank you for the information about the upcoming RFC. While I understand the team is working on a more holistic solution, I believe this PR offers significant immediate value and can coexist with future plans:
Could this PR be considered for merging as an interim solution that allows developers to adopt UIScene now, while the more comprehensive RFC is being refined? The opt-in nature ensures it won't force changes on those not ready and provides a clear migration path for those who are. I'm also happy to adapt this work to align with the RFC once it's available, or close this PR if the team prefers to wait. Just wanted to make the case that this could provide immediate value without blocking future improvements. |
|
This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label. |
feat: Implement UIScene lifecycle for iOS
Summary
This PR implements UIScene lifecycle support for React Native on iOS, resolving the warning:
CLIENT OF UIKIT REQUIRES UPDATE: This process does not adopt UIScene lifecycle. This will become an assert in a future version.Fixes #54739
Problem
Starting with iOS 13, Apple introduced the UIScene lifecycle to support multi-window applications and better separate UI concerns from application-level concerns. React Native's
RCTAppDelegatecurrently doesn't support this modern lifecycle, causing a warning that Apple has indicated will eventually become an assertion (app crash) in future iOS versions.Solution
This PR adds UIScene lifecycle support to
RCTAppDelegatewhile maintaining backward compatibility:Changes Made
1. Modified
RCTAppDelegate.happlication:configurationForConnectingSceneSession:options:method declarationAPI_AVAILABLE(ios(13.0))for backward compatibility2. Modified
RCTAppDelegate.mmUISceneConfigurationthat specifiesRCTSceneDelegateas the scene delegate class3. Created
RCTSceneDelegate.hUIWindowSceneDelegateAPI_AVAILABLE(ios(13.0))4. Created
RCTSceneDelegate.mmscene:willConnectToSession:options:- Sets up the window and React Native root viewsceneDidDisconnect:- Handles scene disconnectionsceneDidBecomeActive:- Scene activation handlingsceneWillResignActive:- Scene deactivation handlingsceneWillEnterForeground:- Foreground transitionsceneDidEnterBackground:- Background transitionRCTAppDelegateto accessRCTReactNativeFactoryandRCTRootViewFactory5. Updated
RNTester/Info.plistUIApplicationSceneManifestconfigurationKey Design Decisions
Backward Compatibility: All UIScene-related code is guarded with
API_AVAILABLE(ios(13.0)), ensuring apps targeting iOS < 13 continue to work.Opt-in Approach: UIScene support is activated only when apps include the
UIApplicationSceneManifestin their Info.plist. Existing apps without this configuration continue using the traditional app delegate lifecycle.Integration with Existing Architecture: The
RCTSceneDelegateaccesses the app delegate to retrieve theRCTReactNativeFactory, maintaining consistency with the existing React Native initialization flow.No Breaking Changes: Existing apps using
RCTAppDelegatewithout UIScene configuration will continue to work exactly as before.Testing
Manual Testing Performed
Expected Behavior
Before this PR:
CLIENT OF UIKIT REQUIRES UPDATE: This process does not adopt UIScene lifecycleAfter this PR:
UIApplicationSceneManifestis present in Info.plistMigration Guide for Users
For New Apps
Include the following in your
Info.plist:For Existing Apps
Option 1: Adopt UIScene (Recommended for iOS 13+)
UIApplicationSceneManifestconfiguration above to your Info.plistRCTAppDelegateOption 2: Continue with Traditional Lifecycle
Changelog
[iOS] [Added] - Implement UIScene lifecycle support for iOS 13+
Additional Notes
RCTAppDelegateclass is marked as deprecated in favor ofRCTReactNativeFactory, but this PR adds UIScene support to maintain compatibility for existing usersReact-RCTAppDelegate.podspec) automatically includes new.hand.mmfiles viapodspec_sources, so no podspec changes were neededScreenshots
UIScene lifecycle adopted successfully - no warnings in Xcode console
Reviewers: @cipolleschi @huntie @cortinico
Please let me know if you'd like any changes to this implementation or if you prefer a different approach!