Преглед изворни кода

rr to reload js, passed e2e

Daniel Zlotin пре 7 година
родитељ
комит
dba0b69c3b

+ 16
- 29
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInitializer.java Прегледај датотеку

@@ -4,13 +4,11 @@ import com.facebook.react.ReactInstanceManager;
4 4
 import com.facebook.react.bridge.ReactContext;
5 5
 import com.reactnativenavigation.NavigationActivity;
6 6
 
7
-import java.util.concurrent.atomic.AtomicBoolean;
8
-
9
-public class NavigationReactInitializer {
7
+public class NavigationReactInitializer implements ReactInstanceManager.ReactInstanceEventListener {
10 8
 
11 9
 	private final ReactInstanceManager reactInstanceManager;
12 10
 	private final DevPermissionRequest devPermissionRequest;
13
-	private final AtomicBoolean appLaunchEmitted = new AtomicBoolean(false);
11
+	private boolean waitingForAppLaunchEvent = true;
14 12
 
15 13
 	public NavigationReactInitializer(ReactInstanceManager reactInstanceManager, boolean isDebug) {
16 14
 		this.reactInstanceManager = reactInstanceManager;
@@ -18,7 +16,7 @@ public class NavigationReactInitializer {
18 16
 	}
19 17
 
20 18
 	public void onActivityCreated(NavigationActivity activity) {
21
-		appLaunchEmitted.set(false);
19
+		waitingForAppLaunchEvent = true;
22 20
 	}
23 21
 
24 22
 	public void onActivityResumed(NavigationActivity activity) {
@@ -37,43 +35,32 @@ public class NavigationReactInitializer {
37 35
 	}
38 36
 
39 37
 	public void onActivityDestroyed(NavigationActivity activity) {
38
+		reactInstanceManager.removeReactInstanceEventListener(this);
40 39
 		if (reactInstanceManager.hasStartedCreatingInitialContext()) {
41 40
 			reactInstanceManager.onHostDestroy(activity);
42 41
 		}
43 42
 	}
44 43
 
45 44
 	private void prepareReactApp() {
45
+		reactInstanceManager.addReactInstanceEventListener(this);
46 46
 		if (shouldCreateContext()) {
47
-			appLaunchEmitted.set(false);
48
-			createReactContext(new Runnable() {
49
-				@Override
50
-				public void run() {
51
-					emitAppLaunchedOnceIfNeeded();
52
-				}
53
-			});
54
-		} else {
55
-			emitAppLaunchedOnceIfNeeded();
47
+			reactInstanceManager.createReactContextInBackground();
48
+		} else if (waitingForAppLaunchEvent) {
49
+			emitAppLaunched();
56 50
 		}
57 51
 	}
58 52
 
59
-	private void emitAppLaunchedOnceIfNeeded() {
60
-		if (appLaunchEmitted.compareAndSet(false, true)) {
61
-			new NavigationEvent(reactInstanceManager.getCurrentReactContext()).appLaunched();
62
-		}
63
-	}
64
-
65
-	private void createReactContext(final Runnable onComplete) {
66
-		reactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
67
-			@Override
68
-			public void onReactContextInitialized(final ReactContext context) {
69
-				reactInstanceManager.removeReactInstanceEventListener(this);
70
-				onComplete.run();
71
-			}
72
-		});
73
-		reactInstanceManager.createReactContextInBackground();
53
+	private void emitAppLaunched() {
54
+		waitingForAppLaunchEvent = false;
55
+		new NavigationEvent(reactInstanceManager.getCurrentReactContext()).appLaunched();
74 56
 	}
75 57
 
76 58
 	private boolean shouldCreateContext() {
77 59
 		return !reactInstanceManager.hasStartedCreatingInitialContext();
78 60
 	}
61
+
62
+	@Override
63
+	public void onReactContextInitialized(final ReactContext context) {
64
+		emitAppLaunched();
65
+	}
79 66
 }

+ 24
- 22
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactGateway.java Прегледај датотеку

@@ -1,18 +1,13 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
-import com.facebook.react.devsupport.DevSupportManager;
4
-import com.facebook.react.devsupport.DevSupportManagerImpl;
5
-import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
6
-import com.facebook.react.devsupport.RedBoxHandler;
7 3
 import com.reactnativenavigation.NavigationActivity;
8 4
 import com.reactnativenavigation.NavigationApplication;
9
-import com.reactnativenavigation.utils.ReflectionUtils;
10 5
 
11 6
 public class ReactGateway {
12 7
 
13
-	public interface JsReloadListener {
14
-		void onJsReload();
15
-	}
8
+//	public interface JsReloadListener {
9
+//		void onJsReload();
10
+//	}
16 11
 
17 12
 	private final NavigationReactNativeHost reactNativeHost;
18 13
 	private final NavigationReactInitializer initializer;
@@ -21,21 +16,28 @@ public class ReactGateway {
21 16
 	public ReactGateway(final NavigationApplication application, final boolean isDebug) {
22 17
 		reactNativeHost = new NavigationReactNativeHost(application, isDebug);
23 18
 
24
-		DevSupportManager devSupportManager = reactNativeHost.getReactInstanceManager().getDevSupportManager();
25
-		ReactInstanceDevCommandsHandler reactInstanceCommandsHandler = (ReactInstanceDevCommandsHandler) ReflectionUtils.getDeclaredField(devSupportManager, "mReactInstanceCommandsHandler");
26
-		String packagerPathForJsBundle = reactNativeHost.getJSMainModuleName();
27
-		boolean enableOnCreate = reactNativeHost.getUseDeveloperSupport();
28
-		RedBoxHandler redBoxHandler = reactNativeHost.getRedBoxHandler();
29
-		DevSupportManagerImpl proxy = new DevSupportManagerImpl(application, reactInstanceCommandsHandler, packagerPathForJsBundle, enableOnCreate, redBoxHandler) {
30
-			@Override
31
-			public void handleReloadJS() {
32
-				super.handleReloadJS();
33
-				// onJsReload
19
+//		DevSupportManager devSupportManager = reactNativeHost.getReactInstanceManager().getDevSupportManager();
20
+//		ReactInstanceDevCommandsHandler reactInstanceCommandsHandler = (ReactInstanceDevCommandsHandler) ReflectionUtils.getDeclaredField(devSupportManager, "mReactInstanceCommandsHandler");
21
+//		String packagerPathForJsBundle = reactNativeHost.getJSMainModuleName();
22
+//		boolean enableOnCreate = reactNativeHost.getUseDeveloperSupport();
23
+//		RedBoxHandler redBoxHandler = reactNativeHost.getRedBoxHandler();
24
+//		DevSupportManagerImpl proxy = new DevSupportManagerImpl(application, reactInstanceCommandsHandler, packagerPathForJsBundle, enableOnCreate, redBoxHandler) {
25
+//			@Override
26
+//			public void handleReloadJS() {
27
+//				super.handleReloadJS();
28
+//
29
+//
30
+//				// onJsReload
34 31
 //				ReactContext currentReactContext = reactNativeHost.getReactInstanceManager().getCurrentReactContext();
35
-//				((NavigationActivity) currentReactContext.getCurrentActivity()).getNavigator().onDestroy();
36
-			}
37
-		};
38
-		ReflectionUtils.setField(reactNativeHost.getReactInstanceManager(), "mDevSupportManager", proxy);
32
+//				if (currentReactContext != null) {
33
+//					NavigationActivity activity = (NavigationActivity) currentReactContext.getCurrentActivity();
34
+//					if (activity != null) {
35
+//						activity.reset();
36
+//					}
37
+//				}
38
+//			}
39
+//		};
40
+//		ReflectionUtils.setField(reactNativeHost.getReactInstanceManager(), "mDevSupportManager", proxy);
39 41
 
40 42
 		initializer = new NavigationReactInitializer(reactNativeHost.getReactInstanceManager(), isDebug);
41 43
 		jsDevReloadHandler = new JsDevReloadHandler(reactNativeHost.getReactInstanceManager());