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,6 +82,14 @@ describe('screen stack', () => {
82 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 93
   it(':ios: set stack root component should be first in stack', async () => {
86 94
     await elementById(testIDs.PUSH_BUTTON).tap();
87 95
     await expect(elementByLabel('Stack Position: 1')).toBeVisible();

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

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

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

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

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

@@ -47,7 +47,7 @@ public class BottomTabsControllerTest extends BaseTest {
47 47
     private ViewController child1;
48 48
     private ViewController child2;
49 49
     private ViewController child3;
50
-    private ViewController child4;
50
+    private StackController child4;
51 51
     private ViewController child5;
52 52
     private Options tabOptions = OptionHelper.createBottomTabOptions();
53 53
     private ImageLoader imageLoaderMock = ImageLoaderMock.mock();
@@ -64,7 +64,7 @@ public class BottomTabsControllerTest extends BaseTest {
64 64
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
65 65
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
66 66
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
67
-        child4 = spy(new SimpleViewController(activity, childRegistry, "child4", tabOptions));
67
+        child4 = spy(createStack("someStack"));
68 68
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
69 69
         when(child5.handleBack(any())).thenReturn(true);
70 70
         tabs = createTabs();
@@ -214,6 +214,20 @@ public class BottomTabsControllerTest extends BaseTest {
214 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 231
     @NonNull
218 232
     private List<ViewController> createTabs() {
219 233
         return Arrays.asList(child1, child2, child3, child4, child5);

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

@@ -32,11 +32,20 @@ class TextScreen extends Component {
32 32
         <Button title='Show Tab Bar' testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
33 33
         <Button title='Show Left Side Menu' testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
34 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 36
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
36 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 49
   onClickPop = async () => {
41 50
     await Navigation.pop(this.props.componentId);
42 51
   }