Browse Source

Fixes pushing bottomTabs - #4172

yogevbd 6 years ago
parent
commit
4ef5e549b8

+ 7
- 0
e2e/ScreenStack.test.js View File

@@ -103,4 +103,11 @@ describe('screen stack', () => {
103 103
     await elementById(testIDs.PUSH_BUTTON).tap();
104 104
     await expect(elementById(testIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
105 105
   });
106
+
107
+  test('push bottom tabs', async () => {
108
+    await elementById(testIDs.PUSH_BUTTON).tap();
109
+    await expect(elementById(testIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
110
+    await elementById(testIDs.PUSH_BOTTOM_TABS_BUTTON).tap();
111
+    await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
112
+  });
106 113
 });

+ 4
- 4
lib/ios/RNNCommandsHandler.m View File

@@ -97,7 +97,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
97 97
 - (void)push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
98 98
 	[self assertReady];
99 99
 	
100
-	RNNRootViewController *newVc = (RNNRootViewController *)[_controllerFactory createLayoutAndSaveToStore:layout];
100
+	UIViewController<RNNLayoutProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
101 101
 	UIViewController *fromVC = [_store findComponentForId:componentId];
102 102
 	
103 103
 	if ([newVc.options.preview.reactTag floatValue] > 0) {
@@ -107,7 +107,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
107 107
 			RNNRootViewController* rootVc = (RNNRootViewController*)vc;
108 108
 			rootVc.previewController = newVc;
109 109
 
110
-      rootVc.previewCallback = ^(UIViewController *vcc) {
110
+      		rootVc.previewCallback = ^(UIViewController *vcc) {
111 111
 				RNNRootViewController* rvc  = (RNNRootViewController*)vcc;
112 112
 				[self->_eventEmitter sendOnPreviewCompleted:componentId previewComponentId:newVc.layoutInfo.componentId];
113 113
 				if ([newVc.options.preview.commit floatValue] > 0) {
@@ -141,8 +141,8 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
141 141
 			});
142 142
 		}
143 143
 	} else {
144
-		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;
145
-		[newVc waitForReactViewRender:(newVc.options.animations.push.waitForRender || animationDelegate) perform:^{
144
+		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.getCurrentChild.isCustomTransitioned) ? newVc : nil;
145
+		[newVc.getCurrentChild waitForReactViewRender:(newVc.options.animations.push.waitForRender || animationDelegate) perform:^{
146 146
 			[_stackManager push:newVc onTop:fromVC animated:newVc.options.animations.push.enable animationDelegate:animationDelegate completion:^{
147 147
 				[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
148 148
 				completion();

+ 2
- 0
lib/ios/RNNLeafProtocol.h View File

@@ -7,4 +7,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
7 7
 
8 8
 - (void)bindViewController:(UIViewController *)viewController;
9 9
 
10
+- (BOOL)isCustomTransitioned;
11
+
10 12
 @end

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

@@ -35,7 +35,6 @@ typedef void (^PreviewCallback)(UIViewController *vc);
35 35
 											options:(RNNNavigationOptions *)options;
36 36
 
37 37
 - (BOOL)isExternalViewController;
38
-- (BOOL)isCustomTransitioned;
39 38
 
40 39
 -(void)onButtonPress:(RNNUIBarButtonItem *)barButtonItem;
41 40
 

+ 1
- 1
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -767,8 +767,8 @@
767 767
 				263905E51E4CAC950023D7D3 /* RNNSideMenuChildVC.m */,
768 768
 				507F43C31FF4F17C00D9425B /* RNNTopTabsViewController.h */,
769 769
 				507F43C41FF4F17C00D9425B /* RNNTopTabsViewController.m */,
770
-				E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */,
771 770
 				E33AC20120B5BA550090DB8A /* RNNSplitViewController.h */,
771
+				E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */,
772 772
 			);
773 773
 			name = "Parent ViewControllers";
774 774
 			sourceTree = "<group>";

+ 95
- 0
playground/src/screens/PushedScreen.js View File

@@ -34,6 +34,7 @@ class PushedScreen extends Component {
34 34
       this.simulateLongRunningTask();
35 35
     }
36 36
     this.onClickPush = this.onClickPush.bind(this);
37
+    this.onClickPushBottomTabs = this.onClickPushBottomTabs.bind(this);
37 38
     this.onClickPop = this.onClickPop.bind(this);
38 39
     this.onClickPopPrevious = this.onClickPopPrevious.bind(this);
39 40
     this.onClickPopToFirstPosition = this.onClickPopToFirstPosition.bind(this);
@@ -80,6 +81,7 @@ class PushedScreen extends Component {
80 81
         <Text testID={testIDs.PUSHED_SCREEN_HEADER} style={styles.h1}>{`Pushed Screen`}</Text>
81 82
         <Text style={styles.h2}>{`Stack Position: ${stackPosition}`}</Text>
82 83
         <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
84
+        <Button title='Push bottomTabs' testID={testIDs.PUSH_BOTTOM_TABS_BUTTON} onPress={this.onClickPushBottomTabs} />
83 85
         {Platform.OS === 'ios' && <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPress={this.onClickPush} onPressIn={this.onClickShowPreview} title='Push Preview' />}
84 86
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
85 87
         <Button title='Pop Previous' testID={testIDs.POP_PREVIOUS_BUTTON} onPress={this.onClickPopPrevious} />
@@ -216,6 +218,99 @@ class PushedScreen extends Component {
216 218
     });
217 219
   }
218 220
 
221
+  async onClickPushBottomTabs() {
222
+    await Navigation.push(this.props.componentId, {
223
+      bottomTabs: {
224
+        id: 'BottomTabs',
225
+        children: [
226
+          {
227
+            stack: {
228
+              id: 'TAB1_ID',
229
+              children: [
230
+                {
231
+                  component: {
232
+                    name: 'navigation.playground.TextScreen',
233
+                    passProps: {
234
+                      text: 'This is tab 1',
235
+                      myFunction: () => 'Hello from a function!'
236
+                    },
237
+                    options: {
238
+                      topBar: {
239
+                        visible: true,
240
+                        animate: false,
241
+                        title: {
242
+                          text: 'React Native Navigation!'
243
+                        }
244
+                      },
245
+                      bottomTab: {
246
+                        text: 'Tab 1',
247
+                        icon: require('../images/one.png'),
248
+                        selectedIcon: require('../images/one.png'),
249
+                        testID: testIDs.FIRST_TAB_BAR_BUTTON
250
+                      }
251
+                    }
252
+                  }
253
+                }
254
+              ],
255
+              options: {
256
+                topBar: {
257
+                  visible: false
258
+                }
259
+              }
260
+            }
261
+          },
262
+          {
263
+            stack: {
264
+              children: [
265
+                {
266
+                  component: {
267
+                    name: 'navigation.playground.TextScreen',
268
+                    passProps: {
269
+                      text: 'This is tab 2'
270
+                    }
271
+                  }
272
+                }
273
+              ],
274
+              options: {
275
+                bottomTab: {
276
+                  text: 'Tab 2',
277
+                  icon: require('../images/two.png'),
278
+                  testID: testIDs.SECOND_TAB_BAR_BUTTON
279
+                }
280
+              }
281
+            }
282
+          },
283
+          {
284
+            component: {
285
+              name: 'navigation.playground.TextScreen',
286
+              passProps: {
287
+                text: 'This is tab 3',
288
+                myFunction: () => 'Hello from a function!'
289
+              },
290
+              options: {
291
+                topBar: {
292
+                  visible: true,
293
+                  animate: false
294
+                },
295
+                bottomTab: {
296
+                  text: 'Tab 3',
297
+                  icon: require('../images/one.png'),
298
+                  selectedIcon: require('../images/one.png')
299
+                }
300
+              }
301
+            }
302
+          }
303
+        ],
304
+        options: {
305
+          bottomTabs: {
306
+            titleDisplayMode: 'alwaysShow',
307
+            testID: testIDs.BOTTOM_TABS_ELEMENT
308
+          }
309
+        }
310
+      }
311
+    });
312
+  }
313
+
219 314
   getStackPosition() {
220 315
     return this.props.stackPosition || 1;
221 316
   }

+ 1
- 0
playground/src/testIDs.js View File

@@ -75,6 +75,7 @@ module.exports = {
75 75
   SIDE_MENU_LAYOUT_INSIDE_BOTTOM_TAB: `SIDE_MENU_LAYOUT_INSIDE_BOTTOM_TAB`,
76 76
   OPEN_SIDE_MENU: `OPEN_SIDE_MENU`,
77 77
   SET_ROOT_BUTTON: `SET_ROOT_BUTTON`,
78
+  PUSH_BOTTOM_TABS_BUTTON: `PUSH_BOTTOM_TABS_BUTTON`,
78 79
   
79 80
   // Elements
80 81
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,