Browse Source

refactored custom view controlles

yogevbd 6 years ago
parent
commit
38d5c5e90d

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

@@ -75,7 +75,7 @@
75 75
 		result = [self createSideMenuChild:node type:RNNSideMenuChildTypeRight];
76 76
 	}
77 77
 	
78
-	else if ( node.isNativeComponent) {
78
+	else if (node.isExternalComponent) {
79 79
 		result = [self createComponent:node nativeComponent:YES];
80 80
 	}
81 81
 	
@@ -93,7 +93,7 @@
93 93
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
94 94
 	options.defaultOptions = _defaultOptions;
95 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 97
 	if (!component.isCustomViewController) {
98 98
 		CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;
99 99
 		[_bridge.uiManager setAvailableSize:availableSize forRootView:component.view];

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

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

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

@@ -17,9 +17,9 @@
17 17
 {
18 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 24
 -(BOOL)isStack
25 25
 {

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

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

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

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

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

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

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

@@ -42,7 +42,7 @@
42 42
 	self.componentId = @"cntId";
43 43
 	self.emitter = nil;
44 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 48
 -(void)testTopBarBackgroundColor_validColor{

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

@@ -22,9 +22,9 @@ describe('LayoutTreeParser', () => {
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 28
         data: { name: 'MyReactComponent', options: LayoutExamples.options, passProps: LayoutExamples.passProps },
29 29
         children: []
30 30
       });
@@ -175,9 +175,9 @@ const singleComponent = {
175 175
   }
176 176
 };
177 177
 
178
-const nativeComponent = {
179
-  nativeComponent: {
180
-    name: 'MyReactComponent',
178
+const externalComponent = {
179
+  externalComponent: {
180
+    className: 'MyReactComponent',
181 181
     options,
182 182
     passProps
183 183
   }
@@ -286,5 +286,5 @@ const LayoutExamples = {
286 286
   sideMenu,
287 287
   topTabs,
288 288
   complexLayout,
289
-  nativeComponent
289
+  externalComponent
290 290
 };

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

@@ -18,8 +18,8 @@ export class LayoutTreeParser {
18 18
       return this._stack(api.stack);
19 19
     } else if (api.component) {
20 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 24
     throw new Error(`unknown LayoutType "${_.keys(api)}"`);
25 25
   }
@@ -99,11 +99,11 @@ export class LayoutTreeParser {
99 99
     };
100 100
   }
101 101
 
102
-  _nativeComponent(api): LayoutNode {
102
+  _externalComponent(api): LayoutNode {
103 103
     return {
104 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 107
       children: []
108 108
     };
109 109
   }

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

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

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

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