Browse Source

handleBack

Daniel Zlotin 7 years ago
parent
commit
7ba1f11976

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/layout/Layout.java View File

4
 
4
 
5
 import com.reactnativenavigation.layout.impl.StackLayout;
5
 import com.reactnativenavigation.layout.impl.StackLayout;
6
 
6
 
7
+//TODO delete
7
 public interface Layout {
8
 public interface Layout {
8
 	void setParentStackLayout(StackLayout stackLayout);
9
 	void setParentStackLayout(StackLayout stackLayout);
9
 
10
 

+ 11
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/NavigationController.java View File

17
 	}
17
 	}
18
 
18
 
19
 	public void push(final ViewController child) {
19
 	public void push(final ViewController child) {
20
-		childControllers.push(child);
21
 		child.setNavigationController(this);
20
 		child.setNavigationController(this);
21
+		childControllers.push(child);
22
 	}
22
 	}
23
 
23
 
24
 	public void pop() {
24
 	public void pop() {
36
 	public boolean isEmpty() {
36
 	public boolean isEmpty() {
37
 		return childControllers.isEmpty();
37
 		return childControllers.isEmpty();
38
 	}
38
 	}
39
+
40
+	@Override
41
+	public boolean handleBack() {
42
+		if (size() > 1) {
43
+			pop();
44
+			return true;
45
+		} else {
46
+			return false;
47
+		}
48
+	}
39
 }
49
 }

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

23
 	void setNavigationController(final NavigationController navigationController) {
23
 	void setNavigationController(final NavigationController navigationController) {
24
 		this.navigationController = navigationController;
24
 		this.navigationController = navigationController;
25
 	}
25
 	}
26
+
27
+	public boolean handleBack() {
28
+		return false;
29
+	}
26
 }
30
 }

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

72
 		NavigationController anotherNavController = new NavigationController(child2);
72
 		NavigationController anotherNavController = new NavigationController(child2);
73
 		assertThat(child2.getNavigationController()).isEqualTo(anotherNavController);
73
 		assertThat(child2.getNavigationController()).isEqualTo(anotherNavController);
74
 	}
74
 	}
75
+
76
+	@Test
77
+	public void handleBack_PopsUnlessSingleChild() throws Exception {
78
+		assertThat(uut.isEmpty()).isTrue();
79
+		assertThat(uut.handleBack()).isFalse();
80
+
81
+		uut.push(child1);
82
+		assertThat(uut.size()).isEqualTo(1);
83
+		assertThat(uut.handleBack()).isFalse();
84
+
85
+		uut.push(child2);
86
+		assertThat(uut.size()).isEqualTo(2);
87
+		assertThat(uut.handleBack()).isTrue();
88
+		assertThat(uut.size()).isEqualTo(1);
89
+	}
75
 }
90
 }

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

33
 		NavigationController nav = new NavigationController(uut);
33
 		NavigationController nav = new NavigationController(uut);
34
 		assertThat(uut.getNavigationController()).isEqualTo(nav);
34
 		assertThat(uut.getNavigationController()).isEqualTo(nav);
35
 	}
35
 	}
36
+
37
+	@Test
38
+	public void handleBackDefaultFalse() throws Exception {
39
+		assertThat(uut.handleBack()).isFalse();
40
+	}
36
 }
41
 }