Browse Source

simple push

Daniel Zlotin 7 years ago
parent
commit
eb7d8b84da

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

63
 		getView().addView(viewController.getView());
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 View File

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

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

1
 package com.reactnativenavigation.viewcontrollers;
1
 package com.reactnativenavigation.viewcontrollers;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
+import android.view.ViewGroup;
4
 
5
 
5
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.mocks.SimpleViewController;
7
 import com.reactnativenavigation.mocks.SimpleViewController;
48
 	public void setRoot_AddsChildControllerView() throws Exception {
49
 	public void setRoot_AddsChildControllerView() throws Exception {
49
 		assertThat(uut.getView().getChildCount()).isZero();
50
 		assertThat(uut.getView().getChildCount()).isZero();
50
 		uut.setRoot(child1);
51
 		uut.setRoot(child1);
51
-		assertHasSingleChildViewOf(child1);
52
+		assertHasSingleChildViewOf(uut, child1);
52
 	}
53
 	}
53
 
54
 
54
 	@Test
55
 	@Test
55
 	public void setRoot_ReplacesExistingChildControllerViews() throws Exception {
56
 	public void setRoot_ReplacesExistingChildControllerViews() throws Exception {
56
 		uut.setRoot(child1);
57
 		uut.setRoot(child1);
57
 		uut.setRoot(child2);
58
 		uut.setRoot(child2);
58
-		assertHasSingleChildViewOf(child2);
59
+		assertHasSingleChildViewOf(uut, child2);
59
 	}
60
 	}
60
 
61
 
61
 	@Test
62
 	@Test
64
 		assertThat(new Navigator(activity).getId()).isNotEqualTo(uut.getId());
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
 }