瀏覽代碼

pass down lifecycle methods to children

Daniel Zlotin 7 年之前
父節點
當前提交
d7411e0a45

+ 8
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java 查看文件

@@ -52,7 +52,6 @@ public abstract class ParentController extends ViewController {
52 52
 		}
53 53
 	}
54 54
 
55
-
56 55
 	@Override
57 56
 	public void onDisappear() {
58 57
 		super.onDisappear();
@@ -60,4 +59,12 @@ public abstract class ParentController extends ViewController {
60 59
 			child.onDisappear();
61 60
 		}
62 61
 	}
62
+
63
+	@Override
64
+	public void onDestroy() {
65
+		super.onDestroy();
66
+		for (ViewController child : getChildControllers()) {
67
+			child.onDestroy();
68
+		}
69
+	}
63 70
 }

+ 9
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java 查看文件

@@ -100,4 +100,13 @@ public class ParentControllerTest extends BaseTest {
100 100
 		verify(child1, times(1)).onDisappear();
101 101
 	}
102 102
 
103
+	@Test
104
+	public void lifecycleMethodsPassDownToChildren_onDestroy() throws Exception {
105
+		ViewController child1 = spy(new SimpleViewController(activity, "child1"));
106
+		children.add(child1);
107
+
108
+		verify(child1, times(0)).onDestroy();
109
+		uut.onDestroy();
110
+		verify(child1, times(1)).onDestroy();
111
+	}
103 112
 }