From 3fdb106f31a8be5e0766a439632e36f2fa036094 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LARRIVIERE <76693792+jblarriviere@users.noreply.github.com> Date: Wed, 18 Jan 2023 06:42:39 -0800 Subject: [PATCH] feat: add initialProps property to RCTAppDelegate (#35848) Summary: Hi there, While upgrading to 0.71 we realised the RCTAppDelegate doesn't offer a way to set custom `initProps` that would depend on `launchOptions`. This PR adds an `initialProps` property to the RCTAppDelegate. This would let us set this property based on `launchOptions` in our implementation of `didFinishLaunchingWithOptions` before calling `[super didFinishLaunchingWithOptions]` Thanks ! ## Changelog [IOS] [ADDED] - Add `initialProps` property to `RCTAppDelegate` Pull Request resolved: https://github.com/facebook/react-native/pull/35848 Reviewed By: rshest Differential Revision: D42543027 Pulled By: cipolleschi fbshipit-source-id: 55374914890445f8193c12a06a943b7796edb457 --- Libraries/AppDelegate/RCTAppDelegate.h | 1 + Libraries/AppDelegate/RCTAppDelegate.mm | 2 +- template/ios/HelloWorld/AppDelegate.mm | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/AppDelegate/RCTAppDelegate.h b/Libraries/AppDelegate/RCTAppDelegate.h index e4e987ad6f0085..b66b994d2c2c43 100644 --- a/Libraries/AppDelegate/RCTAppDelegate.h +++ b/Libraries/AppDelegate/RCTAppDelegate.h @@ -55,6 +55,7 @@ @property (nonatomic, strong) UIWindow *window; @property (nonatomic, strong) RCTBridge *bridge; @property (nonatomic, strong) NSString *moduleName; +@property (nonatomic, strong) NSDictionary *initialProps; /** * It creates a `RCTBridge` using a delegate and some launch options. diff --git a/Libraries/AppDelegate/RCTAppDelegate.mm b/Libraries/AppDelegate/RCTAppDelegate.mm index c498409d051514..e8356af5a0dcf8 100644 --- a/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/Libraries/AppDelegate/RCTAppDelegate.mm @@ -84,7 +84,7 @@ - (BOOL)concurrentRootEnabled - (NSDictionary *)prepareInitialProps { - NSMutableDictionary *initProps = [NSMutableDictionary new]; + NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new]; #ifdef RCT_NEW_ARCH_ENABLED initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); diff --git a/template/ios/HelloWorld/AppDelegate.mm b/template/ios/HelloWorld/AppDelegate.mm index 0cfc4310dd702e..f1de5a6ae1bdd0 100644 --- a/template/ios/HelloWorld/AppDelegate.mm +++ b/template/ios/HelloWorld/AppDelegate.mm @@ -7,6 +7,10 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleName = @"HelloWorld"; + // You can add your custom initial props in the dictionary below. + // They will be passed down to the ViewController used by React Native. + self.initialProps = @{}; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; }