Browse Source

refactored custom view controlles

yogevbd 6 years ago
parent
commit
38d5c5e90d

+ 2
- 2
lib/ios/RNNControllerFactory.m View File

75
 		result = [self createSideMenuChild:node type:RNNSideMenuChildTypeRight];
75
 		result = [self createSideMenuChild:node type:RNNSideMenuChildTypeRight];
76
 	}
76
 	}
77
 	
77
 	
78
-	else if ( node.isNativeComponent) {
78
+	else if (node.isExternalComponent) {
79
 		result = [self createComponent:node nativeComponent:YES];
79
 		result = [self createComponent:node nativeComponent:YES];
80
 	}
80
 	}
81
 	
81
 	
93
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
93
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
94
 	options.defaultOptions = _defaultOptions;
94
 	options.defaultOptions = _defaultOptions;
95
 	NSString* componentId = node.nodeId;
95
 	NSString* componentId = node.nodeId;
96
-	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter isNativeComponent:nativeComponent];
96
+	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter isExternalComponent:nativeComponent];
97
 	if (!component.isCustomViewController) {
97
 	if (!component.isCustomViewController) {
98
 		CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;
98
 		CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;
99
 		[_bridge.uiManager setAvailableSize:availableSize forRootView:component.view];
99
 		[_bridge.uiManager setAvailableSize:availableSize forRootView:component.view];

+ 1
- 1
lib/ios/RNNLayoutNode.h View File

12
 +(instancetype)create:(NSDictionary *)json;
12
 +(instancetype)create:(NSDictionary *)json;
13
 
13
 
14
 -(BOOL)isComponent;
14
 -(BOOL)isComponent;
15
--(BOOL)isNativeComponent;
15
+-(BOOL)isExternalComponent;
16
 -(BOOL)isStack;
16
 -(BOOL)isStack;
17
 -(BOOL)isTabs;
17
 -(BOOL)isTabs;
18
 -(BOOL)isTopTabs;
18
 -(BOOL)isTopTabs;

+ 2
- 2
lib/ios/RNNLayoutNode.m View File

17
 {
17
 {
18
 	return [self.type isEqualToString:@"Component"];
18
 	return [self.type isEqualToString:@"Component"];
19
 }
19
 }
20
--(BOOL)isNativeComponent
20
+-(BOOL)isExternalComponent
21
 {
21
 {
22
-	return [self.type isEqualToString:@"NativeComponent"];
22
+	return [self.type isEqualToString:@"ExternalComponent"];
23
 }
23
 }
24
 -(BOOL)isStack
24
 -(BOOL)isStack
25
 {
25
 {

+ 1
- 1
lib/ios/RNNRootViewController.h View File

23
 			withComponentId:(NSString*)componentId
23
 			withComponentId:(NSString*)componentId
24
 			rootViewCreator:(id<RNNRootViewCreator>)creator
24
 			rootViewCreator:(id<RNNRootViewCreator>)creator
25
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
25
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
26
-		  isNativeComponent:(BOOL)isNativeComponent;
26
+		  isExternalComponent:(BOOL)isExternalComponent;
27
 
27
 
28
 
28
 
29
 -(void)applyTabBarItem;
29
 -(void)applyTabBarItem;

+ 5
- 5
lib/ios/RNNRootViewController.m View File

7
 @interface RNNRootViewController()
7
 @interface RNNRootViewController()
8
 @property (nonatomic, strong) NSString* componentName;
8
 @property (nonatomic, strong) NSString* componentName;
9
 @property (nonatomic) BOOL _statusBarHidden;
9
 @property (nonatomic) BOOL _statusBarHidden;
10
-@property (nonatomic) BOOL isNativeComponent;
10
+@property (nonatomic) BOOL isExternalComponent;
11
 @end
11
 @end
12
 
12
 
13
 @implementation RNNRootViewController
13
 @implementation RNNRootViewController
17
 			withComponentId:(NSString*)componentId
17
 			withComponentId:(NSString*)componentId
18
 			rootViewCreator:(id<RNNRootViewCreator>)creator
18
 			rootViewCreator:(id<RNNRootViewCreator>)creator
19
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
19
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
20
-		  isNativeComponent:(BOOL)isNativeComponent {
20
+		  isExternalComponent:(BOOL)isExternalComponent {
21
 	self = [super init];
21
 	self = [super init];
22
 	self.componentId = componentId;
22
 	self.componentId = componentId;
23
 	self.componentName = name;
23
 	self.componentName = name;
25
 	self.eventEmitter = eventEmitter;
25
 	self.eventEmitter = eventEmitter;
26
 	self.animator = [[RNNAnimator alloc] initWithTransitionOptions:self.options.customTransition];
26
 	self.animator = [[RNNAnimator alloc] initWithTransitionOptions:self.options.customTransition];
27
 	self.creator = creator;
27
 	self.creator = creator;
28
-	self.isNativeComponent = isNativeComponent;
28
+	self.isExternalComponent = isExternalComponent;
29
 	
29
 	
30
-	if (self.isNativeComponent) {
30
+	if (self.isExternalComponent) {
31
 		[self addExternalVC:name];
31
 		[self addExternalVC:name];
32
 	} else {
32
 	} else {
33
 		self.view = [creator createRootView:self.componentName rootViewId:self.componentId];
33
 		self.view = [creator createRootView:self.componentName rootViewId:self.componentId];
99
 }
99
 }
100
 
100
 
101
 - (BOOL)isCustomViewController {
101
 - (BOOL)isCustomViewController {
102
-	return self.isNativeComponent;
102
+	return self.isExternalComponent;
103
 }
103
 }
104
 
104
 
105
 - (BOOL)prefersStatusBarHidden {
105
 - (BOOL)prefersStatusBarHidden {

+ 1
- 1
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m View File

69
 															withComponentId:@"componentId"
69
 															withComponentId:@"componentId"
70
 															rootViewCreator:[[RNNTestRootViewCreator alloc] init]
70
 															rootViewCreator:[[RNNTestRootViewCreator alloc] init]
71
 															   eventEmitter:nil
71
 															   eventEmitter:nil
72
-														  isNativeComponent:NO];
72
+														  isExternalComponent:NO];
73
 	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:vc];
73
 	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:vc];
74
 	[vc viewWillAppear:false];
74
 	[vc viewWillAppear:false];
75
 	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
75
 	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);

+ 1
- 1
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

42
 	self.componentId = @"cntId";
42
 	self.componentId = @"cntId";
43
 	self.emitter = nil;
43
 	self.emitter = nil;
44
 	self.options = [RNNNavigationOptions new];
44
 	self.options = [RNNNavigationOptions new];
45
-	self.uut = [[RNNRootViewController alloc] initWithName:self.pageName withOptions:self.options withComponentId:self.componentId rootViewCreator:self.creator eventEmitter:self.emitter isNativeComponent:NO];
45
+	self.uut = [[RNNRootViewController alloc] initWithName:self.pageName withOptions:self.options withComponentId:self.componentId rootViewCreator:self.creator eventEmitter:self.emitter isExternalComponent:NO];
46
 }
46
 }
47
 
47
 
48
 -(void)testTopBarBackgroundColor_validColor{
48
 -(void)testTopBarBackgroundColor_validColor{

+ 7
- 7
lib/src/commands/LayoutTreeParser.test.ts View File

22
       });
22
       });
23
     });
23
     });
24
 
24
 
25
-    it('native component', () => {
26
-      expect(uut.parse(LayoutExamples.nativeComponent)).toEqual({
27
-        type: LayoutType.NativeComponent,
25
+    it('external component', () => {
26
+      expect(uut.parse(LayoutExamples.externalComponent)).toEqual({
27
+        type: LayoutType.ExternalComponent,
28
         data: { name: 'MyReactComponent', options: LayoutExamples.options, passProps: LayoutExamples.passProps },
28
         data: { name: 'MyReactComponent', options: LayoutExamples.options, passProps: LayoutExamples.passProps },
29
         children: []
29
         children: []
30
       });
30
       });
175
   }
175
   }
176
 };
176
 };
177
 
177
 
178
-const nativeComponent = {
179
-  nativeComponent: {
180
-    name: 'MyReactComponent',
178
+const externalComponent = {
179
+  externalComponent: {
180
+    className: 'MyReactComponent',
181
     options,
181
     options,
182
     passProps
182
     passProps
183
   }
183
   }
286
   sideMenu,
286
   sideMenu,
287
   topTabs,
287
   topTabs,
288
   complexLayout,
288
   complexLayout,
289
-  nativeComponent
289
+  externalComponent
290
 };
290
 };

+ 5
- 5
lib/src/commands/LayoutTreeParser.ts View File

18
       return this._stack(api.stack);
18
       return this._stack(api.stack);
19
     } else if (api.component) {
19
     } else if (api.component) {
20
       return this._component(api.component);
20
       return this._component(api.component);
21
-    } else if (api.nativeComponent) {
22
-      return this._nativeComponent(api.nativeComponent);
21
+    } else if (api.externalComponent) {
22
+      return this._externalComponent(api.externalComponent);
23
     }
23
     }
24
     throw new Error(`unknown LayoutType "${_.keys(api)}"`);
24
     throw new Error(`unknown LayoutType "${_.keys(api)}"`);
25
   }
25
   }
99
     };
99
     };
100
   }
100
   }
101
 
101
 
102
-  _nativeComponent(api): LayoutNode {
102
+  _externalComponent(api): LayoutNode {
103
     return {
103
     return {
104
       id: api.id,
104
       id: api.id,
105
-      type: LayoutType.NativeComponent,
106
-      data: { name: api.name, options: api.options, passProps: api.passProps },
105
+      type: LayoutType.ExternalComponent,
106
+      data: { name: api.className, options: api.options, passProps: api.passProps },
107
       children: []
107
       children: []
108
     };
108
     };
109
   }
109
   }

+ 1
- 1
lib/src/commands/LayoutType.ts View File

7
   SideMenuLeft = 'SideMenuLeft',
7
   SideMenuLeft = 'SideMenuLeft',
8
   SideMenuRight = 'SideMenuRight',
8
   SideMenuRight = 'SideMenuRight',
9
   TopTabs = 'TopTabs',
9
   TopTabs = 'TopTabs',
10
-  NativeComponent = 'NativeComponent'
10
+  ExternalComponent = 'ExternalComponent'
11
 }
11
 }
12
 
12
 
13
 export function isLayoutType(name: string): boolean {
13
 export function isLayoutType(name: string): boolean {

+ 5
- 5
playground/src/screens/WelcomeScreen.js View File

23
     this.onClickShowModal = this.onClickShowModal.bind(this);
23
     this.onClickShowModal = this.onClickShowModal.bind(this);
24
     this.onClickLifecycleScreen = this.onClickLifecycleScreen.bind(this);
24
     this.onClickLifecycleScreen = this.onClickLifecycleScreen.bind(this);
25
     this.onClickPushOptionsScreen = this.onClickPushOptionsScreen.bind(this);
25
     this.onClickPushOptionsScreen = this.onClickPushOptionsScreen.bind(this);
26
-    this.onClickPushNativeComponent = this.onClickPushNativeComponent.bind(this);
26
+    this.onClickPushExternalComponent = this.onClickPushExternalComponent.bind(this);
27
     this.onClickPushOrientationMenuScreen = this.onClickPushOrientationMenuScreen.bind(this);
27
     this.onClickPushOrientationMenuScreen = this.onClickPushOrientationMenuScreen.bind(this);
28
     this.onClickBackHandler = this.onClickBackHandler.bind(this);
28
     this.onClickBackHandler = this.onClickBackHandler.bind(this);
29
     this.onClickPushTopTabsScreen = this.onClickPushTopTabsScreen.bind(this);
29
     this.onClickPushTopTabsScreen = this.onClickPushTopTabsScreen.bind(this);
41
         <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
41
         <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
42
         <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
42
         <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
43
         <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
43
         <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
44
-        <Button title='Push Native Component' testID={testIDs.PUSH_NATIVE_COMPONENT_BUTTON} onPress={this.onClickPushNativeComponent} />
44
+        <Button title='Push Native Component' testID={testIDs.PUSH_NATIVE_COMPONENT_BUTTON} onPress={this.onClickPushExternalComponent} />
45
         {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
45
         {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
46
         {Platform.OS === 'android' && <Button title='Back Handler' testID={testIDs.BACK_HANDLER_BUTTON} onPress={this.onClickBackHandler} />}
46
         {Platform.OS === 'android' && <Button title='Back Handler' testID={testIDs.BACK_HANDLER_BUTTON} onPress={this.onClickBackHandler} />}
47
         <Button title='Show Modal' testID={testIDs.SHOW_MODAL_BUTTON} onPress={this.onClickShowModal} />
47
         <Button title='Show Modal' testID={testIDs.SHOW_MODAL_BUTTON} onPress={this.onClickShowModal} />
233
     });
233
     });
234
   }
234
   }
235
 
235
 
236
-  async onClickPushNativeComponent() {
236
+  async onClickPushExternalComponent() {
237
     await Navigation.push(this.props.componentId, {
237
     await Navigation.push(this.props.componentId, {
238
-      nativeComponent: {
239
-        name: 'RNNCustomViewController',
238
+      externalComponent: {
239
+        className: 'RNNCustomViewController',
240
         options: {
240
         options: {
241
           topBar: {
241
           topBar: {
242
             title: 'pushed',
242
             title: 'pushed',