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
 import android.support.test.uiautomator.By;
3
 import android.support.test.uiautomator.By;
4
 
4
 
5
 import org.junit.FixMethodOrder;
5
 import org.junit.FixMethodOrder;
6
-import org.junit.Ignore;
7
 import org.junit.Test;
6
 import org.junit.Test;
8
 import org.junit.runners.MethodSorters;
7
 import org.junit.runners.MethodSorters;
9
 
8
 
10
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
9
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
11
-@Ignore
12
 public class ApplicationLifecycleTest extends BaseTest {
10
 public class ApplicationLifecycleTest extends BaseTest {
13
 
11
 
14
 	@Test
12
 	@Test

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

32
 		assertMainShown();
32
 		assertMainShown();
33
 		elementByText("PUSH LIFECYCLE SCREEN").click();
33
 		elementByText("PUSH LIFECYCLE SCREEN").click();
34
 		elementByText("onStart!");
34
 		elementByText("onStart!");
35
-		elementByText("Push to test onStop").click();
35
+		elementByText("PUSH TO TEST ONSTOP").click();
36
 		elementByText("Alert");
36
 		elementByText("Alert");
37
 		elementByText("onStop").click();
37
 		elementByText("onStop").click();
38
 	}
38
 	}

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

22
 		this.id = id;
22
 		this.id = id;
23
 		this.name = name;
23
 		this.name = name;
24
 		addView(createReactRootView());
24
 		addView(createReactRootView());
25
-
26
 	}
25
 	}
27
 
26
 
28
 	private View createReactRootView() {
27
 	private View createReactRootView() {
29
-		ReactRootView rootView = new ReactRootView(getContext());
28
+		final ReactRootView rootView = new ReactRootView(getContext());
30
 		Bundle opts = new Bundle();
29
 		Bundle opts = new Bundle();
31
 		opts.putString("id", id);
30
 		opts.putString("id", id);
32
 		rootView.startReactApplication(reactNativeHost.getReactInstanceManager(), name, opts);
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
 		return rootView;
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
 	@Override
42
 	@Override
44
 	protected void onDetachedFromWindow() {
43
 	protected void onDetachedFromWindow() {
45
 		super.onDetachedFromWindow();
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
 import android.view.ViewTreeObserver;
4
 import android.view.ViewTreeObserver;
5
 
5
 
6
 public class UiUtils {
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
 		view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
8
 		view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
9
 			@Override
9
 			@Override
10
 			public boolean onPreDraw() {
10
 			public boolean onPreDraw() {

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

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