From 1a9826b2d6f6d3239363db75d2c6a4e0ccb431f7 Mon Sep 17 00:00:00 2001 From: Srishtyshree Date: Tue, 2 Dec 2025 09:37:42 +0530 Subject: [PATCH 1/2] Add files via upload --- RCTAppDelegate.h | 90 +++++++++++++++++++++++++++++++++++++++ RCTAppDelegate.mm | 100 ++++++++++++++++++++++++++++++++++++++++++++ RCTSceneDelegate.h | 22 ++++++++++ RCTSceneDelegate.mm | 60 ++++++++++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 RCTAppDelegate.h create mode 100644 RCTAppDelegate.mm create mode 100644 RCTSceneDelegate.h create mode 100644 RCTSceneDelegate.mm diff --git a/RCTAppDelegate.h b/RCTAppDelegate.h new file mode 100644 index 000000000000..35bd0d6ab6ab --- /dev/null +++ b/RCTAppDelegate.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import "RCTDefaultReactNativeFactoryDelegate.h" +#import "RCTReactNativeFactory.h" +#import "RCTRootViewFactory.h" + +@class RCTBridge; +@protocol RCTBridgeDelegate; +@protocol RCTComponentViewProtocol; +@class RCTRootView; +@class RCTSurfacePresenterBridgeAdapter; +@protocol RCTDependencyProvider; + +NS_ASSUME_NONNULL_BEGIN + +/** + * @deprecated RCTAppDelegate is deprecated and will be removed in a future version of React Native. Use + `RCTReactNativeFactory` instead. + * + * The RCTAppDelegate is an utility class that implements some base configurations for all the React Native apps. + * It is not mandatory to use it, but it could simplify your AppDelegate code. + * + * To use it, you just need to make your AppDelegate a subclass of RCTAppDelegate: + * + * ```objc + * #import + * @interface AppDelegate: RCTAppDelegate + * @end + * ``` + * + * All the methods implemented by the RCTAppDelegate can be overridden by your AppDelegate if you need to provide a + custom implementation. + * If you need to customize the default implementation, you can invoke `[super ]` and use the returned + object. + * + * Overridable methods + * Shared: + * - (RCTBridge *)createBridgeWithDelegate:(id)delegate launchOptions:(NSDictionary + *)launchOptions; + * - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString*)moduleName initProps:(NSDictionary + *)initProps; + * - (UIViewController *)createRootViewController; + * - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; + * New Architecture: + * - (BOOL)turboModuleEnabled; + * - (BOOL)fabricEnabled; + * - (NSDictionary *)prepareInitialProps + * - (Class)getModuleClassFromName:(const char *)name + * - (std::shared_ptr)getTurboModule:(const std::string &)name + jsInvoker:(std::shared_ptr)jsInvoker + * - (std::shared_ptr)getTurboModule:(const std::string &)name + initParams: + (const facebook::react::ObjCTurboModule::InitParams &)params + * - (id)getModuleInstanceFromClass:(Class)moduleClass + */ +__attribute__((deprecated( + "RCTAppDelegate is deprecated and will be removed in a future version of React Native. Use `RCTReactNativeFactory` instead."))) +@interface RCTAppDelegate : RCTDefaultReactNativeFactoryDelegate + +/// The window object, used to render the UViewControllers +@property (nonatomic, strong, nonnull) UIWindow *window; + +@property (nonatomic, nullable) RCTBridge *bridge + __attribute__((deprecated("The bridge is deprecated and will be removed when removing the legacy architecture."))); +@property (nonatomic, strong, nullable) NSString *moduleName; +@property (nonatomic, strong, nullable) NSDictionary *initialProps; +@property (nonatomic, strong) RCTReactNativeFactory *reactNativeFactory; + +/// If `automaticallyLoadReactNativeWindow` is set to `true`, the React Native window will be loaded automatically. +@property (nonatomic, assign) BOOL automaticallyLoadReactNativeWindow; + +@property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter __attribute__(( + deprecated("The bridge adapter is deprecated and will be removed when removing the legacy architecture."))); +; + +- (RCTRootViewFactory *)rootViewFactory; + +- (UISceneConfiguration *)application:(UIApplication *)application + configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession + options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)); + +@end + +NS_ASSUME_NONNULL_END diff --git a/RCTAppDelegate.mm b/RCTAppDelegate.mm new file mode 100644 index 000000000000..e042f54ee920 --- /dev/null +++ b/RCTAppDelegate.mm @@ -0,0 +1,100 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTAppDelegate.h" +#import +#import +#import +#import +#import +#import +#include +#import +#import "RCTAppSetupUtils.h" +#import "RCTDependencyProvider.h" + +#if RN_DISABLE_OSS_PLUGIN_HEADER +#import +#else +#import +#endif +#import +#import +#import + +using namespace facebook::react; + +@implementation RCTAppDelegate + +- (instancetype)init +{ + if (self = [super init]) { + _automaticallyLoadReactNativeWindow = YES; + } + return self; +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.reactNativeFactory = [[RCTReactNativeFactory alloc] initWithDelegate:self]; + + if (self.automaticallyLoadReactNativeWindow) { + [self loadReactNativeWindow:launchOptions]; + } + + return YES; +} + +- (void)loadReactNativeWindow:(NSDictionary *)launchOptions +{ + UIView *rootView = [self.rootViewFactory viewWithModuleName:self.moduleName + initialProperties:self.initialProps + launchOptions:launchOptions]; + + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + UIViewController *rootViewController = [self createRootViewController]; + [self setRootView:rootView toRootViewController:rootViewController]; + _window.rootViewController = rootViewController; + [_window makeKeyAndVisible]; +} + +- (RCTRootViewFactory *)rootViewFactory +{ + return self.reactNativeFactory.rootViewFactory; +} + +- (RCTBridge *)bridge +{ + return self.rootViewFactory.bridge; +} + +- (RCTSurfacePresenterBridgeAdapter *)bridgeAdapter +{ + return self.rootViewFactory.bridgeAdapter; +} + +- (void)setBridge:(RCTBridge *)bridge +{ + self.reactNativeFactory.rootViewFactory.bridge = bridge; +} + +- (void)setBridgeAdapter:(RCTSurfacePresenterBridgeAdapter *)bridgeAdapter +{ + self.reactNativeFactory.rootViewFactory.bridgeAdapter = bridgeAdapter; +} + +- (UISceneConfiguration *)application:(UIApplication *)application + configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession + options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) +{ + UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:@"Default Configuration" + sessionRole:connectingSceneSession.role]; + configuration.delegateClass = NSClassFromString(@"RCTSceneDelegate"); + return configuration; +} + +@end diff --git a/RCTSceneDelegate.h b/RCTSceneDelegate.h new file mode 100644 index 000000000000..a2101ab2eb48 --- /dev/null +++ b/RCTSceneDelegate.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +@class RCTReactNativeFactory; + +NS_ASSUME_NONNULL_BEGIN + +API_AVAILABLE(ios(13.0)) +@interface RCTSceneDelegate : UIResponder + +@property (nonatomic, strong) UIWindow *window; +@property (nonatomic, weak) RCTReactNativeFactory *reactNativeFactory; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RCTSceneDelegate.mm b/RCTSceneDelegate.mm new file mode 100644 index 000000000000..fd4e6ae53b05 --- /dev/null +++ b/RCTSceneDelegate.mm @@ -0,0 +1,60 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTSceneDelegate.h" +#import "RCTReactNativeFactory.h" +#import "RCTRootViewFactory.h" + +@implementation RCTSceneDelegate + +- (void)scene:(UIScene *)scene + willConnectToSession:(UISceneSession *)session + options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) +{ + if (![scene isKindOfClass:[UIWindowScene class]]) { + return; + } + + UIWindowScene *windowScene = (UIWindowScene *)scene; + + self.window = [[UIWindow alloc] initWithWindowScene:windowScene]; + + if (self.reactNativeFactory) { + UIView *rootView = [self.reactNativeFactory.rootViewFactory + viewWithModuleName:self.reactNativeFactory.rootViewFactory.moduleName + initialProperties:self.reactNativeFactory.rootViewFactory.initialProperties + launchOptions:connectionOptions.notificationResponse.notification.request.content.userInfo]; + + UIViewController *rootViewController = [UIViewController new]; + rootViewController.view = rootView; + self.window.rootViewController = rootViewController; + } + + [self.window makeKeyAndVisible]; +} + +- (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)) +{ +} + +- (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)) +{ +} + +- (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)) +{ +} + +- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) +{ +} + +- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) +{ +} + +@end From 12a18e4199d92c99a3bd2710d08ac13fafef6a22 Mon Sep 17 00:00:00 2001 From: Srishtyshree Date: Tue, 2 Dec 2025 09:42:19 +0530 Subject: [PATCH 2/2] Add UIApplicationSceneManifest to Info.plist --- packages/rn-tester/RNTester/Info.plist | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/rn-tester/RNTester/Info.plist b/packages/rn-tester/RNTester/Info.plist index 373b8322fdc7..b092255e7eda 100644 --- a/packages/rn-tester/RNTester/Info.plist +++ b/packages/rn-tester/RNTester/Info.plist @@ -63,5 +63,22 @@ UIViewControllerBasedStatusBarAppearance + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + RCTSceneDelegate + + + +