Daniel Zlotin преди 7 години
родител
ревизия
7ba1f11976

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/layout/Layout.java Целия файл

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

+ 11
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/NavigationController.java Целия файл

@@ -17,8 +17,8 @@ public class NavigationController extends ViewController {
17 17
 	}
18 18
 
19 19
 	public void push(final ViewController child) {
20
-		childControllers.push(child);
21 20
 		child.setNavigationController(this);
21
+		childControllers.push(child);
22 22
 	}
23 23
 
24 24
 	public void pop() {
@@ -36,4 +36,14 @@ public class NavigationController extends ViewController {
36 36
 	public boolean isEmpty() {
37 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 Целия файл

@@ -23,4 +23,8 @@ public class ViewController {
23 23
 	void setNavigationController(final NavigationController navigationController) {
24 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 Целия файл

@@ -72,4 +72,19 @@ public class NavigationControllerTest extends BaseTest {
72 72
 		NavigationController anotherNavController = new NavigationController(child2);
73 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 Целия файл

@@ -33,4 +33,9 @@ public class ViewControllerTest extends BaseTest {
33 33
 		NavigationController nav = new NavigationController(uut);
34 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
 }