Daniel Zlotin 7 years ago
parent
commit
9337ffc33c

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

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

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/controllers/ActivityLifecycleDelegate.java View File

2
 
2
 
3
 import com.facebook.react.ReactInstanceManager;
3
 import com.facebook.react.ReactInstanceManager;
4
 import com.facebook.react.bridge.ReactContext;
4
 import com.facebook.react.bridge.ReactContext;
5
+import com.facebook.react.modules.core.DeviceEventManagerModule;
5
 import com.reactnativenavigation.NavigationActivity;
6
 import com.reactnativenavigation.NavigationActivity;
6
 import com.reactnativenavigation.react.DevPermissionRequest;
7
 import com.reactnativenavigation.react.DevPermissionRequest;
7
 import com.reactnativenavigation.react.NavigationEventEmitter;
8
 import com.reactnativenavigation.react.NavigationEventEmitter;
60
 
61
 
61
 	private void emitAppLaunchedOnceIfNeeded() {
62
 	private void emitAppLaunchedOnceIfNeeded() {
62
 		if (appLaunchEmitted.compareAndSet(false, true)) {
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 View File

77
 
77
 
78
 	private View createContainer(LayoutNode node) {
78
 	private View createContainer(LayoutNode node) {
79
 		final String name = node.data.optString("name");
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
 		container.setId(CompatUtils.generateViewId());
81
 		container.setId(CompatUtils.generateViewId());
82
 		return container;
82
 		return container;
83
 
83
 

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

5
 import android.view.View;
5
 import android.view.View;
6
 import android.widget.FrameLayout;
6
 import android.widget.FrameLayout;
7
 
7
 
8
-import com.facebook.react.ReactNativeHost;
8
+import com.facebook.react.ReactInstanceManager;
9
 import com.facebook.react.ReactRootView;
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
 import com.reactnativenavigation.react.NavigationEventEmitter;
11
 import com.reactnativenavigation.react.NavigationEventEmitter;
13
 
12
 
14
 public class Container extends FrameLayout {
13
 public class Container extends FrameLayout {
15
-	private final ReactNativeHost reactNativeHost;
14
+
16
 	private final String id;
15
 	private final String id;
17
 	private final String name;
16
 	private final String name;
18
 	private ReactRootView rootView;
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
 		super(activity);
22
 		super(activity);
22
-		this.reactNativeHost = reactNativeHost;
23
+
23
 		this.id = id;
24
 		this.id = id;
24
 		this.name = name;
25
 		this.name = name;
26
+		this.reactInstanceManager = reactInstanceManager;
25
 		addView(createReactRootView());
27
 		addView(createReactRootView());
26
 	}
28
 	}
27
 
29
 
31
 		onStop();
33
 		onStop();
32
 	}
34
 	}
33
 
35
 
36
+
34
 	public void destroy() {
37
 	public void destroy() {
35
 		rootView.unmountReactApplication();
38
 		rootView.unmountReactApplication();
36
 	}
39
 	}
39
 		rootView = new ReactRootView(getContext());
42
 		rootView = new ReactRootView(getContext());
40
 		Bundle opts = new Bundle();
43
 		Bundle opts = new Bundle();
41
 		opts.putString("id", id);
44
 		opts.putString("id", id);
42
-		rootView.startReactApplication(reactNativeHost.getReactInstanceManager(), name, opts);
45
+		rootView.startReactApplication(reactInstanceManager, name, opts);
43
 		rootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
46
 		rootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
44
 			@Override
47
 			@Override
45
 			public void onAttachedToReactInstance(final ReactRootView reactRootView) {
48
 			public void onAttachedToReactInstance(final ReactRootView reactRootView) {
51
 	}
54
 	}
52
 
55
 
53
 	private void onStart() {
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
 	private void onStop() {
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 View File

1
 package com.reactnativenavigation.react;
1
 package com.reactnativenavigation.react;
2
 
2
 
3
 import com.facebook.react.bridge.Arguments;
3
 import com.facebook.react.bridge.Arguments;
4
-import com.facebook.react.bridge.ReactContext;
5
 import com.facebook.react.bridge.WritableMap;
4
 import com.facebook.react.bridge.WritableMap;
6
 
5
 
7
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
6
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
13
 
12
 
14
 	private final RCTDeviceEventEmitter emitter;
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
 	public void appLaunched() {
19
 	public void appLaunched() {

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/layout/ContainerStackTest.java View File

36
 	private Container createContainer(final NavigationActivity context) {
36
 	private Container createContainer(final NavigationActivity context) {
37
 		ReactNativeHost reactNativeHost = mock(ReactNativeHost.class);
37
 		ReactNativeHost reactNativeHost = mock(ReactNativeHost.class);
38
 		when(reactNativeHost.getReactInstanceManager()).thenReturn(mock(ReactInstanceManager.class));
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
 }