Browse Source

Fix crash when pushing into a stack located in BottomTabs

Guy Carmeli 6 years ago
parent
commit
fa0a23c95b

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

82
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
82
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
83
   });
83
   });
84
 
84
 
85
+  it('push into a stack from BottomTabs', async () => {
86
+    await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
87
+    await elementById(testIDs.PUSH_BUTTON).tap();
88
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
89
+    await elementById(testIDs.POP_BUTTON).tap();
90
+    await expect(elementByLabel('This is tab 1')).toBeVisible();
91
+  });
92
+
85
   it(':ios: set stack root component should be first in stack', async () => {
93
   it(':ios: set stack root component should be first in stack', async () => {
86
     await elementById(testIDs.PUSH_BUTTON).tap();
94
     await elementById(testIDs.PUSH_BUTTON).tap();
87
     await expect(elementByLabel('Stack Position: 1')).toBeVisible();
95
     await expect(elementByLabel('Stack Position: 1')).toBeVisible();

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java View File

62
 
62
 
63
     @Override
63
     @Override
64
     public void mergeOptions(Options options) {
64
     public void mergeOptions(Options options) {
65
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, view));
65
+        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
66
         super.mergeOptions(options);
66
         super.mergeOptions(options);
67
     }
67
     }
68
 
68
 

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java View File

45
 
45
 
46
     @Override
46
     @Override
47
     public void mergeOptions(Options options) {
47
     public void mergeOptions(Options options) {
48
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, view));
48
+        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
49
         super.mergeOptions(options);
49
         super.mergeOptions(options);
50
     }
50
     }
51
 
51
 

+ 16
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

47
     private ViewController child1;
47
     private ViewController child1;
48
     private ViewController child2;
48
     private ViewController child2;
49
     private ViewController child3;
49
     private ViewController child3;
50
-    private ViewController child4;
50
+    private StackController child4;
51
     private ViewController child5;
51
     private ViewController child5;
52
     private Options tabOptions = OptionHelper.createBottomTabOptions();
52
     private Options tabOptions = OptionHelper.createBottomTabOptions();
53
     private ImageLoader imageLoaderMock = ImageLoaderMock.mock();
53
     private ImageLoader imageLoaderMock = ImageLoaderMock.mock();
64
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
64
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
65
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
65
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
66
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
66
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
67
-        child4 = spy(new SimpleViewController(activity, childRegistry, "child4", tabOptions));
67
+        child4 = spy(createStack("someStack"));
68
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
68
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
69
         when(child5.handleBack(any())).thenReturn(true);
69
         when(child5.handleBack(any())).thenReturn(true);
70
         tabs = createTabs();
70
         tabs = createTabs();
214
         verify(child5, times(1)).sendOnNavigationButtonPressed("btn1");
214
         verify(child5, times(1)).sendOnNavigationButtonPressed("btn1");
215
     }
215
     }
216
 
216
 
217
+    @Test
218
+    public void push() {
219
+        uut.selectTab(3);
220
+
221
+        SimpleViewController stackChild = new SimpleViewController(activity, childRegistry, "stackChild", new Options());
222
+        SimpleViewController stackChild2 = new SimpleViewController(activity, childRegistry, "stackChild", new Options());
223
+        disablePushAnimation(stackChild, stackChild2);
224
+
225
+        child4.push(stackChild, new CommandListenerAdapter());
226
+        assertThat(child4.size()).isOne();
227
+        child4.push(stackChild2, new CommandListenerAdapter());
228
+        assertThat(child4.size()).isEqualTo(2);
229
+    }
230
+
217
     @NonNull
231
     @NonNull
218
     private List<ViewController> createTabs() {
232
     private List<ViewController> createTabs() {
219
         return Arrays.asList(child1, child2, child3, child4, child5);
233
         return Arrays.asList(child1, child2, child3, child4, child5);

+ 9
- 0
playground/src/screens/TextScreen.js View File

32
         <Button title='Show Tab Bar' testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
32
         <Button title='Show Tab Bar' testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
33
         <Button title='Show Left Side Menu' testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
33
         <Button title='Show Left Side Menu' testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
34
         <Button title='Show Right Side Menu' testID={testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('right')} />
34
         <Button title='Show Right Side Menu' testID={testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('right')} />
35
+        <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
35
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
36
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
36
       </View>
37
       </View>
37
     );
38
     );
38
   }
39
   }
39
 
40
 
41
+  onClickPush = async () => {
42
+    await Navigation.push(this.props.componentId, {
43
+      component: {
44
+        name: 'navigation.playground.PushedScreen'
45
+      }
46
+    });
47
+  }
48
+
40
   onClickPop = async () => {
49
   onClickPop = async () => {
41
     await Navigation.pop(this.props.componentId);
50
     await Navigation.pop(this.props.componentId);
42
   }
51
   }