Parcourir la source

getInitialProps ios support (#2606)

yogevbd il y a 6 ans
Parent
révision
d6356133bf

+ 1
- 0
ios/RCCManager.h Voir le fichier

@@ -13,6 +13,7 @@
13 13
 -(UIWindow*)getAppWindow;
14 14
 -(void)setAppStyle:(NSDictionary*)appStyle;
15 15
 -(NSDictionary*)getAppStyle;
16
+-(NSDictionary*)getInitialProps;
16 17
 
17 18
 -(void)registerController:(UIViewController*)controller componentId:(NSString*)componentId componentType:(NSString*)componentType;
18 19
 -(id)getControllerWithId:(NSString*)componentId componentType:(NSString*)componentType;

+ 6
- 0
ios/RCCManager.m Voir le fichier

@@ -10,6 +10,7 @@
10 10
 @property (nonatomic, strong) RCTBridge *sharedBridge;
11 11
 @property (nonatomic, strong) NSURL *bundleURL;
12 12
 @property (nonatomic, strong, readwrite) NSDictionary *globalAppStyle;
13
+@property (nonatomic, strong) NSDictionary *launchOptions;
13 14
 @end
14 15
 
15 16
 @implementation RCCManager
@@ -46,6 +47,10 @@
46 47
   return self;
47 48
 }
48 49
 
50
+- (NSDictionary *)getInitialProps {
51
+  return _launchOptions;
52
+}
53
+
49 54
 -(void)clearModuleRegistry
50 55
 {
51 56
   [self.modulesRegistry removeAllObjects];
@@ -155,6 +160,7 @@
155 160
 {
156 161
   if (self.sharedBridge) return;
157 162
   
163
+  self.launchOptions = launchOptions;
158 164
   self.bundleURL = bundleURL;
159 165
   self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
160 166
   

+ 5
- 0
ios/RCCManagerModule.m Voir le fichier

@@ -480,4 +480,9 @@ RCT_EXPORT_METHOD(
480 480
     [RCCManagerModule cancelAllRCCViewControllerReactTouches];
481 481
 }
482 482
 
483
+RCT_EXPORT_METHOD(getInitialProps:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
484
+{
485
+    resolve([[RCCManager sharedInstance] getInitialProps]);
486
+}
487
+
483 488
 @end

+ 6
- 1
src/Navigation.js Voir le fichier

@@ -131,6 +131,10 @@ function dismissInAppNotification(params = {}) {
131 131
   return platformSpecific.dismissInAppNotification(params);
132 132
 }
133 133
 
134
+async function getInitialProps() {
135
+  return await platformSpecific.getInitialProps();
136
+}
137
+
134 138
 async function startTabBasedApp(params) {
135 139
   try {
136 140
     return await platformSpecific.startTabBasedApp(params);
@@ -200,5 +204,6 @@ export default {
200 204
   clearEventHandler: clearEventHandler,
201 205
   handleDeepLink: handleDeepLink,
202 206
   isAppLaunched: isAppLaunched,
203
-  isRootLaunched: isRootLaunched
207
+  isRootLaunched: isRootLaunched,
208
+  getInitialProps: getInitialProps
204 209
 };

+ 3
- 0
src/deprecated/controllers/index.js Voir le fichier

@@ -128,6 +128,9 @@ var Controllers = {
128 128
       _validateDrawerProps(layout);
129 129
       _processProperties(_.get(layout, 'props.appStyle', {}));
130 130
       return await RCCManager.setRootController(layout, animationType, passProps);
131
+    },
132
+    getInitialProps: async function() {
133
+      return await RCCManager.getInitialProps();
131 134
     }
132 135
   },
133 136
 

+ 6
- 1
src/deprecated/platformSpecificDeprecated.ios.js Voir le fichier

@@ -586,6 +586,10 @@ function dismissLightBox(params) {
586 586
   Modal.dismissLightBox();
587 587
 }
588 588
 
589
+async function getInitialProps() {
590
+  return await ControllerRegistry.getInitialProps();
591
+}
592
+
589 593
 function showInAppNotification(params) {
590 594
   if (!params.screen) {
591 595
     console.error('showInAppNotification(params): params.screen is required');
@@ -721,5 +725,6 @@ export default {
721 725
   navigatorToggleNavBar,
722 726
   showContextualMenu,
723 727
   dismissContextualMenu,
724
-  getCurrentlyVisibleScreenId
728
+  getCurrentlyVisibleScreenId,
729
+  getInitialProps
725 730
 };