Browse Source

Implement push into modal

closes #2487
Guy Carmeli 7 years ago
parent
commit
0bd6e7dfcd

+ 7
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ModalsTest.java View File

109
 		elementByText("DISMISS ALL MODALS").click();
109
 		elementByText("DISMISS ALL MODALS").click();
110
 		assertMainShown();
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 View File

59
 		return null;
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
 		private final Dialog dialog;
70
 		private final Dialog dialog;
65
 
71
 
66
 		Modal(final ViewController viewController) {
72
 		Modal(final ViewController viewController) {

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.support.annotation.NonNull;
4
 import android.support.annotation.NonNull;
5
+import android.support.annotation.Nullable;
5
 import android.view.ViewGroup;
6
 import android.view.ViewGroup;
6
 import android.widget.FrameLayout;
7
 import android.widget.FrameLayout;
7
 
8
 
173
 			promise.reject(new Throwable("Nothing to pop"));
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 View File

56
 		this.parentController = parentController;
56
 		this.parentController = parentController;
57
 	}
57
 	}
58
 
58
 
59
-    void performOnParentStack(Task<StackController> task) {
59
+    boolean performOnParentStack(Task<StackController> task) {
60
 	    if (parentController instanceof StackController) {
60
 	    if (parentController instanceof StackController) {
61
             task.run((StackController) parentController);
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
     void performOnParentStack(Task<StackController> accept, Runnable  reject) {
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
             reject.run();
73
             reject.run();
70
         }
74
         }
71
     }
75
     }

+ 9
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

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 View File

24
     this.onClickDismissAllPreviousModals = this.onClickDismissAllPreviousModals.bind(this);
24
     this.onClickDismissAllPreviousModals = this.onClickDismissAllPreviousModals.bind(this);
25
     this.onClickDismissFirstInStack = this.onClickDismissFirstInStack.bind(this);
25
     this.onClickDismissFirstInStack = this.onClickDismissFirstInStack.bind(this);
26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
26
     this.onClickDismissAllModals = this.onClickDismissAllModals.bind(this);
27
+    this.onClickPushScreen = this.onClickPushScreen.bind(this);
27
   }
28
   }
28
 
29
 
29
   render() {
30
   render() {
35
         <Button title="Dismiss Modal" testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
36
         <Button title="Dismiss Modal" testID={testIDs.DISMISS_MODAL_BUTTON} onPress={this.onClickDismissModal} />
36
         <Button title="Dismiss Unknown Modal" testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
37
         <Button title="Dismiss Unknown Modal" testID={testIDs.DISMISS_UNKNOWN_MODAL_BUTTON} onPress={this.onClickDismissUnknownModal} />
37
         <Button title="Dismiss All Modals" testID={testIDs.DISMISS_ALL_MODALS_BUTTON} onPress={this.onClickDismissAllModals} />
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
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissPreviousModal} />) : undefined}
40
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" testID={testIDs.DISMISS_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissPreviousModal} />) : undefined}
39
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" testID={testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissAllPreviousModals} />) : undefined}
41
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" testID={testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON} onPress={this.onClickDismissAllPreviousModals} />) : undefined}
40
         {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" testID={testIDs.DISMISS_FIRST_MODAL_BUTTON} onPress={this.onClickDismissFirstInStack} />) : undefined}
42
         {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" testID={testIDs.DISMISS_FIRST_MODAL_BUTTON} onPress={this.onClickDismissFirstInStack} />) : undefined}
79
     Navigation.dismissAllModals();
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
   getModalPosition() {
93
   getModalPosition() {
83
     return (this.props.modalPosition || 1);
94
     return (this.props.modalPosition || 1);
84
   }
95
   }