Daniel Zlotin преди 8 години
родител
ревизия
8e375a48a6

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Целия файл

64
 	}
64
 	}
65
 
65
 
66
 	public void onAppear() {
66
 	public void onAppear() {
67
+		//
68
+	}
69
+
70
+	public void onDisappear() {
71
+		//
67
 	}
72
 	}
68
 
73
 
69
 	@Override
74
 	@Override

+ 16
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Целия файл

83
 	}
83
 	}
84
 
84
 
85
 	@Test
85
 	@Test
86
-	public void onAppear_WhenVisibleOnScreen() throws Exception {
86
+	public void onAppear_WhenShown() throws Exception {
87
 		ViewController spy = spy(uut);
87
 		ViewController spy = spy(uut);
88
 		spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
88
 		spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
89
 		Assertions.assertThat(spy.getView()).isNotShown();
89
 		Assertions.assertThat(spy.getView()).isNotShown();
107
 
107
 
108
 		verify(spy, times(1)).onAppear();
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