Daniel Zlotin il y a 7 ans
Parent
révision
eb7d8b84da

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Voir le fichier

@@ -63,7 +63,9 @@ public class Navigator extends ViewController {
63 63
 		getView().addView(viewController.getView());
64 64
 	}
65 65
 
66
-	public void push(final ViewController onViewController, final ViewController viewController) {
67
-
66
+	public void push(final String onId, final ViewController viewController) {
67
+		if (root instanceof StackController) {
68
+			((StackController) root).push(viewController);
69
+		}
68 70
 	}
69 71
 }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Voir le fichier

@@ -6,10 +6,10 @@ import android.support.annotation.Nullable;
6 6
 import android.view.View;
7 7
 
8 8
 public abstract class ViewController {
9
-	private View view;
10 9
 	private final Activity activity;
10
+	private final String id;
11
+	private View view;
11 12
 	private StackController stackController;
12
-	private String id;
13 13
 
14 14
 	public ViewController(Activity activity, String id) {
15 15
 		this.activity = activity;

+ 28
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4
+import android.view.ViewGroup;
4 5
 
5 6
 import com.reactnativenavigation.BaseTest;
6 7
 import com.reactnativenavigation.mocks.SimpleViewController;
@@ -48,14 +49,14 @@ public class NavigatorTest extends BaseTest {
48 49
 	public void setRoot_AddsChildControllerView() throws Exception {
49 50
 		assertThat(uut.getView().getChildCount()).isZero();
50 51
 		uut.setRoot(child1);
51
-		assertHasSingleChildViewOf(child1);
52
+		assertHasSingleChildViewOf(uut, child1);
52 53
 	}
53 54
 
54 55
 	@Test
55 56
 	public void setRoot_ReplacesExistingChildControllerViews() throws Exception {
56 57
 		uut.setRoot(child1);
57 58
 		uut.setRoot(child2);
58
-		assertHasSingleChildViewOf(child2);
59
+		assertHasSingleChildViewOf(uut, child2);
59 60
 	}
60 61
 
61 62
 	@Test
@@ -64,8 +65,30 @@ public class NavigatorTest extends BaseTest {
64 65
 		assertThat(new Navigator(activity).getId()).isNotEqualTo(uut.getId());
65 66
 	}
66 67
 
67
-	private void assertHasSingleChildViewOf(ViewController vc) {
68
-		assertThat(uut.getView().getChildCount()).isEqualTo(1);
69
-		assertThat(uut.getView().getChildAt(0)).isEqualTo(vc.getView()).isNotNull();
68
+	@Test
69
+	public void push() throws Exception {
70
+		StackController stackController = new StackController(activity, "stack1");
71
+		stackController.push(child1);
72
+		uut.setRoot(stackController);
73
+
74
+		assertHasSingleChildViewOf(uut, stackController);
75
+		assertHasSingleChildViewOf(stackController, child1);
76
+
77
+		uut.push(child1.getId(), child2);
78
+
79
+		assertHasSingleChildViewOf(uut, stackController);
80
+		assertHasSingleChildViewOf(stackController, child2);
81
+	}
82
+
83
+	@Test
84
+	public void push_InvalidPushWithoutAStack_DoesNothing() throws Exception {
85
+		uut.setRoot(child1);
86
+		uut.push(child1.getId(), child2);
87
+		assertHasSingleChildViewOf(uut, child1);
88
+	}
89
+
90
+	private void assertHasSingleChildViewOf(ViewController parent, ViewController child) {
91
+		assertThat(((ViewGroup) parent.getView()).getChildCount()).isEqualTo(1);
92
+		assertThat(((ViewGroup) parent.getView()).getChildAt(0)).isEqualTo(child.getView()).isNotNull();
70 93
 	}
71 94
 }