Ver código fonte

android screen lifecycle

Daniel Zlotin 7 anos atrás
pai
commit
9af8b141b2

+ 1
- 1
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ScreenLifecycleTest.java Ver arquivo

5
 import org.junit.Ignore;
5
 import org.junit.Ignore;
6
 import org.junit.Test;
6
 import org.junit.Test;
7
 
7
 
8
-@Ignore
9
 public class ScreenLifecycleTest extends BaseTest {
8
 public class ScreenLifecycleTest extends BaseTest {
10
 
9
 
11
 	@Test
10
 	@Test
19
 	}
18
 	}
20
 
19
 
21
 	@Test
20
 	@Test
21
+	@Ignore
22
 	public void unmountIsCalledWhenPopped() throws Exception {
22
 	public void unmountIsCalledWhenPopped() throws Exception {
23
 		launchTheApp();
23
 		launchTheApp();
24
 		assertMainShown();
24
 		assertMainShown();

+ 16
- 26
lib/android/app/src/main/java/com/reactnativenavigation/layout/ReactRootViewController.java Ver arquivo

7
 
7
 
8
 import com.facebook.react.ReactInstanceManager;
8
 import com.facebook.react.ReactInstanceManager;
9
 import com.facebook.react.ReactRootView;
9
 import com.facebook.react.ReactRootView;
10
+import com.reactnativenavigation.react.NavigationEvent;
10
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 
12
 
12
 public class ReactRootViewController extends ViewController {
13
 public class ReactRootViewController extends ViewController {
26
 //		reactRootView.unmountReactApplication();
27
 //		reactRootView.unmountReactApplication();
27
 //	}
28
 //	}
28
 
29
 
29
-//	@Override
30
-//	public void onViewAttachedToWindow(final View v) {
31
-//		//
32
-//	}
33
-//
34
-//	@Override
35
-//	public void onViewDetachedFromWindow(final View v) {
36
-//		onStop();
37
-//	}
38
-//
39
-//	private void onStart() {
40
-//		new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStart(id);
41
-//	}
42
-//
43
-//	private void onStop() {
44
-//		new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStop(id);
45
-//	}
30
+	@Override
31
+	public void onAppear() {
32
+		super.onAppear();
33
+		new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStart(getId());
34
+	}
46
 
35
 
47
-//	@Override
48
-//	public void onStart() {
49
-//		super.onStart();
50
-//		if (attachedToReactInstance) {
51
-//			new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStart(id);
52
-//		} else {
53
-//			throw new RuntimeException("Not yet attached to react");
54
-//		}
55
-//	}
36
+	@Override
37
+	public void onDisappear() {
38
+		super.onDisappear();
39
+		new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStop(getId());
40
+	}
41
+
42
+	@Override
43
+	protected boolean isViewShown() {
44
+		return super.isViewShown() && attachedToReactInstance;
45
+	}
56
 
46
 
57
 	@NonNull
47
 	@NonNull
58
 	@Override
48
 	@Override