Ver código fonte

Stack depth android (#2559)

* Support creating stack with multiple children

* Add e2e
Guy Carmeli 7 anos atrás
pai
commit
735ac83cbb
Nenhuma conta vinculada ao e-mail do autor do commit

+ 9
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ScreenStackTest.java Ver arquivo

@@ -45,4 +45,13 @@ public class ScreenStackTest extends BaseTest {
45 45
         elementByText("POP TO ROOT").click();
46 46
         assertMainShown();
47 47
     }
48
+
49
+    @Test
50
+    public void pushStackWithMultipleChildren() throws Exception {
51
+        elementByText("SHOW MODAL").click();
52
+        elementByText("SHOW MODAL WITH STACK").click();
53
+        assertExists(By.text("Screen 2"));
54
+        device().pressBack();
55
+        assertExists(By.text("Screen 1"));
56
+    }
48 57
 }

+ 7
- 3
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Ver arquivo

@@ -101,9 +101,13 @@ public class LayoutFactory {
101 101
 
102 102
 	private ViewController createStack(LayoutNode node) {
103 103
 		StackController stackController = new StackController(activity, node.id);
104
-		for (LayoutNode child : node.children) {
105
-			stackController.animatePush(create(child), new NoOpPromise());
106
-		}
104
+        for (int i = 0; i < node.children.size(); i++) {
105
+            if (i < node.children.size() - 1) {
106
+                stackController.push(create(node.children.get(i)), new NoOpPromise());
107
+            } else {
108
+                stackController.animatePush(create(node.children.get(i)), new NoOpPromise());
109
+            }
110
+        }
107 111
 		return stackController;
108 112
 	}
109 113
 

+ 14
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Ver arquivo

@@ -44,6 +44,20 @@ public class StackController extends ParentController <StackLayout> {
44 44
         stackLayout.clearOptions();
45 45
     }
46 46
 
47
+    public void push(ViewController child, final Promise promise) {
48
+        final ViewController toRemove = stack.peek();
49
+
50
+        child.setParentController(this);
51
+        stack.push(child.getId(), child);
52
+        View enteringView = child.getView();
53
+        getView().addView(enteringView);
54
+
55
+        if (toRemove != null) {
56
+            getView().removeView(toRemove.getView());
57
+        }
58
+        promise.resolve(child.getId());
59
+    }
60
+
47 61
     public void animatePush(final ViewController child, final Promise promise) {
48 62
 		final ViewController toRemove = stack.peek();
49 63
 

+ 27
- 0
playground/src/screens/ModalScreen.js Ver arquivo

@@ -25,6 +25,7 @@ class ModalScreen extends Component {
25 25
     this.onClickDismissFirstInStack = this.onClickDismissFirstInStack.bind(this);
26 26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
27 27
     this.onClickPushScreen = this.onClickPushScreen.bind(this);
28
+    this.onShowModalWithDeepStack = this.onShowModalWithDeepStack.bind(this);
28 29
   }
29 30
 
30 31
   render() {
@@ -37,6 +38,7 @@ class ModalScreen extends Component {
37 38
         <Button title="Dismiss Unknown Modal" testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
38 39
         <Button title="Dismiss All Modals" testID={testIDs.DISMISS_ALL_MODALS_BUTTON} onPress={this.onClickDismissAllModals} />
39 40
         <Button title="Push screen" testID={testIDs.PUSH_BUTTON} onPress={this.onClickPushScreen} />
41
+        <Button title="Show Modal With Stack" testID={testIDs.PUSH_BUTTON} onPress={this.onShowModalWithDeepStack} />
40 42
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissPreviousModal} />) : undefined}
41 43
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" testID={testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissAllPreviousModals} />) : undefined}
42 44
         {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" testID={testIDs.DISMISS_FIRST_MODAL_BUTTON} onPress={this.onClickDismissFirstInStack} />) : undefined}
@@ -92,6 +94,31 @@ class ModalScreen extends Component {
92 94
     });
93 95
   }
94 96
 
97
+  onShowModalWithDeepStack() {
98
+    Navigation.showModal({
99
+      stack: {
100
+        children: [
101
+          {
102
+            component: {
103
+              name: `navigation.playground.TextScreen`,
104
+              passProps: {
105
+                text: 'Screen 1'
106
+              }
107
+            }
108
+          },
109
+          {
110
+            component: {
111
+              name: `navigation.playground.TextScreen`,
112
+              passProps: {
113
+                text: 'Screen 2'
114
+              }
115
+            }
116
+          }
117
+        ]
118
+      }
119
+    });
120
+  }
121
+
95 122
   getModalPosition() {
96 123
     return (this.props.modalPosition || 1);
97 124
   }