Daniel Zlotin 7 년 전
부모
커밋
9337ffc33c

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java 파일 보기

@@ -12,6 +12,7 @@ import com.reactnativenavigation.react.NavigationReactNativeHost;
12 12
 
13 13
 public abstract class NavigationApplication extends Application implements ReactApplication {
14 14
 
15
+	//TODO un mock this
15 16
 	NavigationReactNativeHost reactNativeHost;
16 17
 	ActivityLifecycleDelegate activityLifecycle;
17 18
 
@@ -28,6 +29,7 @@ public abstract class NavigationApplication extends Application implements React
28 29
 
29 30
 	public abstract boolean isDebug();
30 31
 
32
+	//TODO inline this
31 33
 	void init() {
32 34
 		CommandsHandler commandsHandler = new CommandsHandler(this);
33 35
 		reactNativeHost = new NavigationReactNativeHost(this, isDebug(), commandsHandler);

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/controllers/ActivityLifecycleDelegate.java 파일 보기

@@ -2,6 +2,7 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import com.facebook.react.ReactInstanceManager;
4 4
 import com.facebook.react.bridge.ReactContext;
5
+import com.facebook.react.modules.core.DeviceEventManagerModule;
5 6
 import com.reactnativenavigation.NavigationActivity;
6 7
 import com.reactnativenavigation.react.DevPermissionRequest;
7 8
 import com.reactnativenavigation.react.NavigationEventEmitter;
@@ -60,7 +61,7 @@ public class ActivityLifecycleDelegate {
60 61
 
61 62
 	private void emitAppLaunchedOnceIfNeeded() {
62 63
 		if (appLaunchEmitted.compareAndSet(false, true)) {
63
-			new NavigationEventEmitter(reactInstanceManager.getCurrentReactContext()).appLaunched();
64
+			new NavigationEventEmitter(reactInstanceManager.getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).appLaunched();
64 65
 		}
65 66
 	}
66 67
 

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutFactory.java 파일 보기

@@ -77,7 +77,7 @@ public class LayoutFactory {
77 77
 
78 78
 	private View createContainer(LayoutNode node) {
79 79
 		final String name = node.data.optString("name");
80
-		Container container = new Container(activity, reactNativeHost, node.id, name);
80
+		Container container = new Container(activity, node.id, name, reactNativeHost.getReactInstanceManager());
81 81
 		container.setId(CompatUtils.generateViewId());
82 82
 		return container;
83 83
 

+ 12
- 13
lib/android/app/src/main/java/com/reactnativenavigation/layout/containers/Container.java 파일 보기

@@ -5,23 +5,25 @@ import android.os.Bundle;
5 5
 import android.view.View;
6 6
 import android.widget.FrameLayout;
7 7
 
8
-import com.facebook.react.ReactNativeHost;
8
+import com.facebook.react.ReactInstanceManager;
9 9
 import com.facebook.react.ReactRootView;
10
-import com.facebook.react.bridge.ReactContext;
11
-import com.reactnativenavigation.NavigationApplication;
10
+import com.facebook.react.modules.core.DeviceEventManagerModule;
12 11
 import com.reactnativenavigation.react.NavigationEventEmitter;
13 12
 
14 13
 public class Container extends FrameLayout {
15
-	private final ReactNativeHost reactNativeHost;
14
+
16 15
 	private final String id;
17 16
 	private final String name;
18 17
 	private ReactRootView rootView;
18
+	private final ReactInstanceManager reactInstanceManager;
19
+
19 20
 
20
-	public Container(Activity activity, ReactNativeHost reactNativeHost, String id, String name) {
21
+	public Container(Activity activity, String id, String name, final ReactInstanceManager reactInstanceManager) {
21 22
 		super(activity);
22
-		this.reactNativeHost = reactNativeHost;
23
+
23 24
 		this.id = id;
24 25
 		this.name = name;
26
+		this.reactInstanceManager = reactInstanceManager;
25 27
 		addView(createReactRootView());
26 28
 	}
27 29
 
@@ -31,6 +33,7 @@ public class Container extends FrameLayout {
31 33
 		onStop();
32 34
 	}
33 35
 
36
+
34 37
 	public void destroy() {
35 38
 		rootView.unmountReactApplication();
36 39
 	}
@@ -39,7 +42,7 @@ public class Container extends FrameLayout {
39 42
 		rootView = new ReactRootView(getContext());
40 43
 		Bundle opts = new Bundle();
41 44
 		opts.putString("id", id);
42
-		rootView.startReactApplication(reactNativeHost.getReactInstanceManager(), name, opts);
45
+		rootView.startReactApplication(reactInstanceManager, name, opts);
43 46
 		rootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
44 47
 			@Override
45 48
 			public void onAttachedToReactInstance(final ReactRootView reactRootView) {
@@ -51,15 +54,11 @@ public class Container extends FrameLayout {
51 54
 	}
52 55
 
53 56
 	private void onStart() {
54
-		new NavigationEventEmitter(reactContext()).containerStart(id);
57
+		new NavigationEventEmitter(reactInstanceManager.getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).containerStart(id);
55 58
 	}
56 59
 
57 60
 	private void onStop() {
58
-		new NavigationEventEmitter(reactContext()).containerStop(id);
61
+		new NavigationEventEmitter(reactInstanceManager.getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).containerStop(id);
59 62
 	}
60 63
 
61
-	private ReactContext reactContext() {
62
-		//TODO this is wrong, we should inject reactContext somehow
63
-		return ((NavigationApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
64
-	}
65 64
 }

+ 2
- 3
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationEventEmitter.java 파일 보기

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3 3
 import com.facebook.react.bridge.Arguments;
4
-import com.facebook.react.bridge.ReactContext;
5 4
 import com.facebook.react.bridge.WritableMap;
6 5
 
7 6
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
@@ -13,8 +12,8 @@ public class NavigationEventEmitter {
13 12
 
14 13
 	private final RCTDeviceEventEmitter emitter;
15 14
 
16
-	public NavigationEventEmitter(ReactContext reactContext) {
17
-		this.emitter = reactContext.getJSModule(RCTDeviceEventEmitter.class);
15
+	public NavigationEventEmitter(final RCTDeviceEventEmitter emitter) {
16
+		this.emitter = emitter;
18 17
 	}
19 18
 
20 19
 	public void appLaunched() {

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/layout/ContainerStackTest.java 파일 보기

@@ -36,6 +36,6 @@ public class ContainerStackTest extends BaseTest {
36 36
 	private Container createContainer(final NavigationActivity context) {
37 37
 		ReactNativeHost reactNativeHost = mock(ReactNativeHost.class);
38 38
 		when(reactNativeHost.getReactInstanceManager()).thenReturn(mock(ReactInstanceManager.class));
39
-		return new Container(context, reactNativeHost, "id", "name");
39
+		return new Container(context, "id", "name", reactNativeHost.getReactInstanceManager());
40 40
 	}
41 41
 }