Browse Source

android onAppear

Daniel Zlotin 7 years ago
parent
commit
8e375a48a6

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

@@ -64,6 +64,11 @@ public abstract class ViewController implements ViewTreeObserver.OnGlobalLayoutL
64 64
 	}
65 65
 
66 66
 	public void onAppear() {
67
+		//
68
+	}
69
+
70
+	public void onDisappear() {
71
+		//
67 72
 	}
68 73
 
69 74
 	@Override

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

@@ -83,7 +83,7 @@ public class ViewControllerTest extends BaseTest {
83 83
 	}
84 84
 
85 85
 	@Test
86
-	public void onAppear_WhenVisibleOnScreen() throws Exception {
86
+	public void onAppear_WhenShown() throws Exception {
87 87
 		ViewController spy = spy(uut);
88 88
 		spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
89 89
 		Assertions.assertThat(spy.getView()).isNotShown();
@@ -107,5 +107,20 @@ public class ViewControllerTest extends BaseTest {
107 107
 
108 108
 		verify(spy, times(1)).onAppear();
109 109
 	}
110
+
111
+	@Test
112
+	public void onDisappear_WhenNotShown_AfterOnAppearWasCalled() throws Exception {
113
+		ViewController spy = spy(uut);
114
+		Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
115
+		Assertions.assertThat(spy.getView()).isShown();
116
+		spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
117
+		verify(spy, times(1)).onAppear();
118
+		verify(spy, times(0)).onDisappear();
119
+
120
+		spy.getView().setVisibility(View.GONE);
121
+		spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
122
+		Assertions.assertThat(spy.getView()).isNotShown();
123
+		verify(spy, times(1)).onDisappear();
124
+	}
110 125
 }
111 126