Skip to content

Commit 89be5ab

Browse files
jblarrivierekelset
authored andcommitted
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: #35848 Reviewed By: rshest Differential Revision: D42543027 Pulled By: cipolleschi fbshipit-source-id: 55374914890445f8193c12a06a943b7796edb457
1 parent 38e5fa6 commit 89be5ab

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Libraries/AppDelegate/RCTAppDelegate.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
@property (nonatomic, strong) UIWindow *window;
5656
@property (nonatomic, strong) RCTBridge *bridge;
5757
@property (nonatomic, strong) NSString *moduleName;
58+
@property (nonatomic, strong) NSDictionary *initialProps;
5859

5960
/**
6061
* It creates a `RCTBridge` using a delegate and some launch options.

Libraries/AppDelegate/RCTAppDelegate.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ - (BOOL)concurrentRootEnabled
8484

8585
- (NSDictionary *)prepareInitialProps
8686
{
87-
NSMutableDictionary *initProps = [NSMutableDictionary new];
87+
NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];
8888

8989
#ifdef RCT_NEW_ARCH_ENABLED
9090
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);

template/ios/HelloWorld/AppDelegate.mm

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ @implementation AppDelegate
77
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
88
{
99
self.moduleName = @"HelloWorld";
10+
// You can add your custom initial props in the dictionary below.
11+
// They will be passed down to the ViewController used by React Native.
12+
self.initialProps = @{};
13+
1014
return [super application:application didFinishLaunchingWithOptions:launchOptions];
1115
}
1216

0 commit comments

Comments
 (0)