Browse Source

fix nullify view on unmount

Daniel Zlotin 7 years ago
parent
commit
5d92701be5

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

72
 	}
72
 	}
73
 
73
 
74
 	public void onDestroy() {
74
 	public void onDestroy() {
75
-		if (view != null) {
76
-			view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
77
-		}
78
 		if (isShown) {
75
 		if (isShown) {
79
 			isShown = false;
76
 			isShown = false;
80
 			onDisappear();
77
 			onDisappear();
81
 		}
78
 		}
79
+		if (view != null) {
80
+			view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
81
+			view = null;
82
+		}
82
 	}
83
 	}
83
 
84
 
84
 	@Override
85
 	@Override

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

11
 import org.junit.Test;
11
 import org.junit.Test;
12
 import org.robolectric.Shadows;
12
 import org.robolectric.Shadows;
13
 
13
 
14
+import java.lang.reflect.Field;
15
+
14
 import static org.assertj.core.api.Java6Assertions.assertThat;
16
 import static org.assertj.core.api.Java6Assertions.assertThat;
15
 import static org.mockito.Mockito.mock;
17
 import static org.mockito.Mockito.mock;
16
 import static org.mockito.Mockito.spy;
18
 import static org.mockito.Mockito.spy;
150
 		view.getViewTreeObserver().dispatchOnGlobalLayout();
152
 		view.getViewTreeObserver().dispatchOnGlobalLayout();
151
 		verify(spy, times(0)).onAppear();
153
 		verify(spy, times(0)).onAppear();
152
 		verify(spy, times(0)).onDisappear();
154
 		verify(spy, times(0)).onDisappear();
155
+
156
+		Field field = ViewController.class.getDeclaredField("view");
157
+		field.setAccessible(true);
158
+		assertThat(field.get(spy)).isNull();
153
 	}
159
 	}
154
 
160
 
155
 	@Test
161
 	@Test