Browse Source

getInitialProps ios support (#2606)

yogevbd 6 years ago
parent
commit
d6356133bf

+ 1
- 0
ios/RCCManager.h View File

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

+ 6
- 0
ios/RCCManager.m View File

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

+ 5
- 0
ios/RCCManagerModule.m View File

480
     [RCCManagerModule cancelAllRCCViewControllerReactTouches];
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
 @end
488
 @end

+ 6
- 1
src/Navigation.js View File

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

+ 3
- 0
src/deprecated/controllers/index.js View File

128
       _validateDrawerProps(layout);
128
       _validateDrawerProps(layout);
129
       _processProperties(_.get(layout, 'props.appStyle', {}));
129
       _processProperties(_.get(layout, 'props.appStyle', {}));
130
       return await RCCManager.setRootController(layout, animationType, passProps);
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 View File

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