Browse Source

first implemenetation of #965

Daniel Zlotin 7 years ago
parent
commit
859156e0a1

+ 0
- 2
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -3,12 +3,10 @@ package com.reactnativenavigation.e2e.androide2e;
3 3
 import android.support.test.uiautomator.By;
4 4
 
5 5
 import org.junit.FixMethodOrder;
6
-import org.junit.Ignore;
7 6
 import org.junit.Test;
8 7
 import org.junit.runners.MethodSorters;
9 8
 
10 9
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
11
-@Ignore
12 10
 public class ApplicationLifecycleTest extends BaseTest {
13 11
 
14 12
 	@Test

+ 1
- 1
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java View File

@@ -32,7 +32,7 @@ public class TopLevelApiTest extends BaseTest {
32 32
 		assertMainShown();
33 33
 		elementByText("PUSH LIFECYCLE SCREEN").click();
34 34
 		elementByText("onStart!");
35
-		elementByText("Push to test onStop").click();
35
+		elementByText("PUSH TO TEST ONSTOP").click();
36 36
 		elementByText("Alert");
37 37
 		elementByText("onStop").click();
38 38
 	}

+ 22
- 12
lib/android/app/src/main/java/com/reactnativenavigation/layout/containers/Container.java View File

@@ -22,29 +22,39 @@ public class Container extends FrameLayout {
22 22
 		this.id = id;
23 23
 		this.name = name;
24 24
 		addView(createReactRootView());
25
-
26 25
 	}
27 26
 
28 27
 	private View createReactRootView() {
29
-		ReactRootView rootView = new ReactRootView(getContext());
28
+		final ReactRootView rootView = new ReactRootView(getContext());
30 29
 		Bundle opts = new Bundle();
31 30
 		opts.putString("id", id);
32 31
 		rootView.startReactApplication(reactNativeHost.getReactInstanceManager(), name, opts);
32
+		rootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
33
+			@Override
34
+			public void onAttachedToReactInstance(final ReactRootView reactRootView) {
35
+				rootView.setEventListener(null);
36
+				onStart();
37
+			}
38
+		});
33 39
 		return rootView;
34 40
 	}
35 41
 
36
-	//    @Override
37
-//    protected void onAttachedToWindow() {
38
-//        super.onAttachedToWindow();
39
-//        NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
40
-//                .containerStart(id);
41
-//    }
42
-
43 42
 	@Override
44 43
 	protected void onDetachedFromWindow() {
45 44
 		super.onDetachedFromWindow();
46
-		//TODO this is wrong
47
-		ReactContext reactContext = ((NavigationApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
48
-		new NavigationEventEmitter(reactContext).containerStart(id);
45
+		onStop();
46
+	}
47
+
48
+	private void onStart() {
49
+		new NavigationEventEmitter(reactContext()).containerStart(id);
50
+	}
51
+
52
+	private void onStop() {
53
+		new NavigationEventEmitter(reactContext()).containerStop(id);
54
+	}
55
+
56
+	private ReactContext reactContext() {
57
+		//TODO this is wrong, we should inject reactContext somehow
58
+		return ((NavigationApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
49 59
 	}
50 60
 }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/UiUtils.java View File

@@ -4,7 +4,7 @@ import android.view.View;
4 4
 import android.view.ViewTreeObserver;
5 5
 
6 6
 public class UiUtils {
7
-	public static void runOnPreDraw(final View view, final Runnable task) {
7
+	public static void runOnPreDrawOnce(final View view, final Runnable task) {
8 8
 		view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
9 9
 			@Override
10 10
 			public boolean onPreDraw() {

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java View File

@@ -14,12 +14,12 @@ import static org.mockito.Mockito.verifyZeroInteractions;
14 14
 
15 15
 public class UiUtilsTest extends BaseTest {
16 16
 	@Test
17
-	public void runOnPreDraw() throws Exception {
17
+	public void runOnPreDrawOnce() throws Exception {
18 18
 		View view = Shadow.newInstanceOf(View.class);
19 19
 		Runnable task = mock(Runnable.class);
20 20
 		verifyZeroInteractions(task);
21 21
 
22
-		UiUtils.runOnPreDraw(view, task);
22
+		UiUtils.runOnPreDrawOnce(view, task);
23 23
 		view.getViewTreeObserver().dispatchOnPreDraw();
24 24
 		verify(task, times(1)).run();
25 25
 	}