Преглед изворни кода

basic navigationController

Daniel Zlotin пре 7 година
родитељ
комит
79c8dc94dc

+ 25
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/NavigationController.java Прегледај датотеку

@@ -0,0 +1,25 @@
1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import java.util.Stack;
4
+
5
+public class NavigationController extends ViewController {
6
+	private Stack<ViewController> childControllers = new Stack<>();
7
+
8
+	public NavigationController(ViewController... childControllers) {
9
+		for (ViewController childController : childControllers) {
10
+			this.childControllers.push(childController);
11
+		}
12
+	}
13
+
14
+	public Stack<ViewController> getChildControllers() {
15
+		return childControllers;
16
+	}
17
+
18
+	public void push(final ViewController child) {
19
+		childControllers.push(child);
20
+	}
21
+
22
+	public void pop() {
23
+		childControllers.pop();
24
+	}
25
+}

+ 47
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigationControllerTest.java Прегледај датотеку

@@ -0,0 +1,47 @@
1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import com.reactnativenavigation.BaseTest;
4
+
5
+import org.junit.Test;
6
+
7
+import static org.assertj.core.api.Java6Assertions.assertThat;
8
+
9
+public class NavigationControllerTest extends BaseTest {
10
+
11
+	@Test
12
+	public void isAViewController() throws Exception {
13
+		assertThat(new NavigationController()).isInstanceOf(ViewController.class);
14
+	}
15
+
16
+	@Test
17
+	public void holdsAStackOfViewControllers() throws Exception {
18
+		assertThat(new NavigationController().getChildControllers()).isEmpty();
19
+		ViewController c1 = new ViewController();
20
+		ViewController c2 = new ViewController();
21
+		ViewController c3 = new ViewController();
22
+		assertThat(new NavigationController(c1, c2, c3).getChildControllers()).containsExactly(c1, c2, c3);
23
+	}
24
+
25
+	@Test
26
+	public void push() throws Exception {
27
+		NavigationController uut = new NavigationController();
28
+		ViewController c1 = new ViewController();
29
+		assertThat(uut.getChildControllers()).isEmpty();
30
+		uut.push(c1);
31
+		assertThat(uut.getChildControllers()).containsExactly(c1);
32
+	}
33
+
34
+	@Test
35
+	public void pop() throws Exception {
36
+		NavigationController uut = new NavigationController();
37
+		ViewController c1 = new ViewController();
38
+		ViewController c2 = new ViewController();
39
+		uut.push(c1);
40
+		uut.push(c2);
41
+		assertThat(uut.getChildControllers()).containsExactly(c1, c2);
42
+		uut.pop();
43
+		assertThat(uut.getChildControllers()).containsExactly(c1);
44
+		uut.pop();
45
+		assertThat(uut.getChildControllers()).isEmpty();
46
+	}
47
+}