Pārlūkot izejas kodu

fix nullify view on unmount

Daniel Zlotin 7 gadus atpakaļ
vecāks
revīzija
5d92701be5

+ 4
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Parādīt failu

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

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Parādīt failu

@@ -11,6 +11,8 @@ import org.assertj.android.api.Assertions;
11 11
 import org.junit.Test;
12 12
 import org.robolectric.Shadows;
13 13
 
14
+import java.lang.reflect.Field;
15
+
14 16
 import static org.assertj.core.api.Java6Assertions.assertThat;
15 17
 import static org.mockito.Mockito.mock;
16 18
 import static org.mockito.Mockito.spy;
@@ -150,6 +152,10 @@ public class ViewControllerTest extends BaseTest {
150 152
 		view.getViewTreeObserver().dispatchOnGlobalLayout();
151 153
 		verify(spy, times(0)).onAppear();
152 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 161
 	@Test