Просмотр исходного кода

Implement push into modal

closes #2487
Guy Carmeli 7 лет назад
Родитель
Сommit
0bd6e7dfcd

+ 7
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ModalsTest.java Просмотреть файл

@@ -109,4 +109,11 @@ public class ModalsTest extends BaseTest {
109 109
 		elementByText("DISMISS ALL MODALS").click();
110 110
 		assertMainShown();
111 111
 	}
112
+
113
+	@Test
114
+    public void pushIntoModal() throws Exception {
115
+        elementByText("SHOW MODAL").click();
116
+        elementByText("PUSH SCREEN").click();
117
+        assertExists(By.text("Pushed from modal"));
118
+    }
112 119
 }

+ 8
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java Просмотреть файл

@@ -59,8 +59,14 @@ public class ModalStack {
59 59
 		return null;
60 60
 	}
61 61
 
62
-	private static class Modal {
63
-		private final ViewController viewController;
62
+	@Nullable
63
+    ViewController findControllerById(String id) {
64
+        Modal modal = findModalByContainerId(id);
65
+        return modal != null ? modal.viewController : null;
66
+    }
67
+
68
+    private static class Modal {
69
+		public final ViewController viewController;
64 70
 		private final Dialog dialog;
65 71
 
66 72
 		Modal(final ViewController viewController) {

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Просмотреть файл

@@ -2,6 +2,7 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.support.annotation.NonNull;
5
+import android.support.annotation.Nullable;
5 6
 import android.view.ViewGroup;
6 7
 import android.widget.FrameLayout;
7 8
 
@@ -173,4 +174,11 @@ public class Navigator extends ParentController {
173 174
 			promise.reject(new Throwable("Nothing to pop"));
174 175
 		}
175 176
 	}
177
+
178
+    @Nullable
179
+    @Override
180
+    public ViewController findControllerById(String id) {
181
+        ViewController controllerById = super.findControllerById(id);
182
+        return controllerById != null ? controllerById : modalStack.findControllerById(id);
183
+    }
176 184
 }

+ 8
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Просмотреть файл

@@ -56,16 +56,20 @@ public abstract class ViewController implements ViewTreeObserver.OnGlobalLayoutL
56 56
 		this.parentController = parentController;
57 57
 	}
58 58
 
59
-    void performOnParentStack(Task<StackController> task) {
59
+    boolean performOnParentStack(Task<StackController> task) {
60 60
 	    if (parentController instanceof StackController) {
61 61
             task.run((StackController) parentController);
62
+            return true;
62 63
         }
64
+        if (this instanceof StackController) {
65
+	        task.run((StackController) this);
66
+            return true;
67
+        }
68
+        return false;
63 69
     }
64 70
 
65 71
     void performOnParentStack(Task<StackController> accept, Runnable  reject) {
66
-        if (parentController instanceof StackController) {
67
-            accept.run((StackController) parentController);
68
-        } else {
72
+        if (!performOnParentStack(accept)) {
69 73
             reject.run();
70 74
         }
71 75
     }

+ 9
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Просмотреть файл

@@ -282,4 +282,13 @@ public class NavigatorTest extends BaseTest {
282 282
 			}
283 283
 		});
284 284
 	}
285
+
286
+	@Test
287
+    public void pushIntoModal() throws Exception {
288
+        StackController stackController = newStack();
289
+        stackController.push(child1);
290
+        uut.showModal(stackController, new MockPromise());
291
+        uut.push(stackController.getId(), child2);
292
+        assertIsChildById(stackController.getView(), child2.getView());
293
+    }
285 294
 }

+ 11
- 0
playground/src/containers/ModalScreen.js Просмотреть файл

@@ -24,6 +24,7 @@ class ModalScreen extends Component {
24 24
     this.onClickDismissAllPreviousModals = this.onClickDismissAllPreviousModals.bind(this);
25 25
     this.onClickDismissFirstInStack = this.onClickDismissFirstInStack.bind(this);
26 26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
27
+    this.onClickPushScreen = this.onClickPushScreen.bind(this);
27 28
   }
28 29
 
29 30
   render() {
@@ -35,6 +36,7 @@ class ModalScreen extends Component {
35 36
         <Button title="Dismiss Modal" testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
36 37
         <Button title="Dismiss Unknown Modal" testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
37 38
         <Button title="Dismiss All Modals" testID={testIDs.DISMISS_ALL_MODALS_BUTTON} onPress={this.onClickDismissAllModals} />
39
+        <Button title="Push screen" testID={testIDs.PUSH_BUTTON} onPress={this.onClickPushScreen} />
38 40
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissPreviousModal} />) : undefined}
39 41
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" testID={testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissAllPreviousModals} />) : undefined}
40 42
         {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" testID={testIDs.DISMISS_FIRST_MODAL_BUTTON} onPress={this.onClickDismissFirstInStack} />) : undefined}
@@ -79,6 +81,15 @@ class ModalScreen extends Component {
79 81
     Navigation.dismissAllModals();
80 82
   }
81 83
 
84
+  onClickPushScreen() {
85
+    Navigation.push(this.props.containerId, {
86
+      name: `navigation.playground.TextScreen`,
87
+      passProps: {
88
+        text: 'Pushed from modal'
89
+      }
90
+    });
91
+  }
92
+
82 93
   getModalPosition() {
83 94
     return (this.props.modalPosition || 1);
84 95
   }