Browse Source

rootViewCreator

Daniel Zlotin 7 years ago
parent
commit
343ea16123

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

8
 import com.reactnativenavigation.controllers.CommandsHandler;
8
 import com.reactnativenavigation.controllers.CommandsHandler;
9
 import com.reactnativenavigation.react.DevPermissionRequestImpl;
9
 import com.reactnativenavigation.react.DevPermissionRequestImpl;
10
 import com.reactnativenavigation.react.NavigationReactNativeHost;
10
 import com.reactnativenavigation.react.NavigationReactNativeHost;
11
+import com.reactnativenavigation.react.NavigationReactRootViewCreator;
11
 
12
 
12
 public abstract class NavigationApplication extends Application implements ReactApplication {
13
 public abstract class NavigationApplication extends Application implements ReactApplication {
13
 	public static NavigationApplication instance;
14
 	public static NavigationApplication instance;
47
 		Config config = new Config();
48
 		Config config = new Config();
48
 		config.reactNativeHost = new NavigationReactNativeHost(this, isDebug());
49
 		config.reactNativeHost = new NavigationReactNativeHost(this, isDebug());
49
 		config.activityLifecycleDelegate = new ActivityLifecycleDelegate(config.reactNativeHost.getReactInstanceManager(), new DevPermissionRequestImpl());
50
 		config.activityLifecycleDelegate = new ActivityLifecycleDelegate(config.reactNativeHost.getReactInstanceManager(), new DevPermissionRequestImpl());
50
-		config.commandsHandler = new CommandsHandler();
51
+		config.commandsHandler = new CommandsHandler(new NavigationReactRootViewCreator());
51
 		return config;
52
 		return config;
52
 	}
53
 	}
53
 }
54
 }

+ 9
- 6
lib/android/app/src/main/java/com/reactnativenavigation/controllers/CommandsHandler.java View File

6
 import com.reactnativenavigation.layout.LayoutFactory;
6
 import com.reactnativenavigation.layout.LayoutFactory;
7
 import com.reactnativenavigation.layout.LayoutNode;
7
 import com.reactnativenavigation.layout.LayoutNode;
8
 import com.reactnativenavigation.layout.StackLayout;
8
 import com.reactnativenavigation.layout.StackLayout;
9
-import com.reactnativenavigation.react.NavigationReactRootViewCreator;
9
+import com.reactnativenavigation.react.ReactRootViewCreator;
10
 
10
 
11
 import org.json.JSONObject;
11
 import org.json.JSONObject;
12
 
12
 
13
 public class CommandsHandler {
13
 public class CommandsHandler {
14
 
14
 
15
+	private final ReactRootViewCreator reactRootViewCreator;
16
+
17
+	public CommandsHandler(ReactRootViewCreator reactRootViewCreator) {
18
+		this.reactRootViewCreator = reactRootViewCreator;
19
+	}
20
+
15
 	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
21
 	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
16
 		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
22
 		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
17
-		LayoutFactory factory =
18
-				new LayoutFactory(activity, new NavigationReactRootViewCreator());
19
-
23
+		LayoutFactory factory = new LayoutFactory(activity, reactRootViewCreator);
20
 		final View rootView = factory.create(layoutTreeRoot);
24
 		final View rootView = factory.create(layoutTreeRoot);
21
 		activity.setContentView(rootView);
25
 		activity.setContentView(rootView);
22
 	}
26
 	}
23
 
27
 
24
 	public void push(final NavigationActivity activity, String onContainerId, JSONObject layoutTree) {
28
 	public void push(final NavigationActivity activity, String onContainerId, JSONObject layoutTree) {
25
 		final LayoutNode layoutNode = LayoutNode.parse(layoutTree);
29
 		final LayoutNode layoutNode = LayoutNode.parse(layoutTree);
26
-		LayoutFactory factory =
27
-				new LayoutFactory(activity, new NavigationReactRootViewCreator());
30
+		LayoutFactory factory = new LayoutFactory(activity, reactRootViewCreator);
28
 		final View rootView = factory.create(layoutNode);
31
 		final View rootView = factory.create(layoutNode);
29
 		((StackLayout) activity.getContentView()).push(rootView);
32
 		((StackLayout) activity.getContentView()).push(rootView);
30
 	}
33
 	}

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

5
 
5
 
6
 import com.reactnativenavigation.NavigationApplication;
6
 import com.reactnativenavigation.NavigationApplication;
7
 import com.reactnativenavigation.react.NavigationEventEmitter;
7
 import com.reactnativenavigation.react.NavigationEventEmitter;
8
+import com.reactnativenavigation.react.ReactRootViewCreator;
8
 
9
 
9
 public class Container extends FrameLayout {
10
 public class Container extends FrameLayout {
10
 	private final String id;
11
 	private final String id;
11
 
12
 
12
-	public Container(Activity activity, LayoutFactory.ReactRootViewCreator reactRootViewCreator, String id, String name) {
13
+	public Container(Activity activity, ReactRootViewCreator reactRootViewCreator, String id, String name) {
13
 		super(activity);
14
 		super(activity);
14
 		this.id = id;
15
 		this.id = id;
15
 		addView(reactRootViewCreator.create(activity, id, name));
16
 		addView(reactRootViewCreator.create(activity, id, name));

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutFactory.java View File

8
 
8
 
9
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
9
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
10
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
10
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
11
+import com.reactnativenavigation.react.ReactRootViewCreator;
11
 import com.reactnativenavigation.utils.CompatUtils;
12
 import com.reactnativenavigation.utils.CompatUtils;
12
 
13
 
13
 import java.util.List;
14
 import java.util.List;
14
 
15
 
15
 public class LayoutFactory {
16
 public class LayoutFactory {
16
 
17
 
17
-	public interface ReactRootViewCreator {
18
-		View create(Activity activity, String id, String name);
19
-	}
20
-
21
 	private final Activity activity;
18
 	private final Activity activity;
22
 	private final ReactRootViewCreator reactRootViewCreator;
19
 	private final ReactRootViewCreator reactRootViewCreator;
23
 	private final BottomTabsCreator bottomTabsCreator; // TODO: revisit this, may not be needed
20
 	private final BottomTabsCreator bottomTabsCreator; // TODO: revisit this, may not be needed

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

11
 public class NavigationModule extends ReactContextBaseJavaModule {
11
 public class NavigationModule extends ReactContextBaseJavaModule {
12
 	private static final String NAME = "RNNBridgeModule";
12
 	private static final String NAME = "RNNBridgeModule";
13
 
13
 
14
-	public NavigationModule(ReactApplicationContext reactContext) {
14
+	public NavigationModule(final ReactApplicationContext reactContext) {
15
 		super(reactContext);
15
 		super(reactContext);
16
 	}
16
 	}
17
 
17
 

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactRootViewCreator.java View File

6
 
6
 
7
 import com.facebook.react.ReactRootView;
7
 import com.facebook.react.ReactRootView;
8
 import com.reactnativenavigation.NavigationApplication;
8
 import com.reactnativenavigation.NavigationApplication;
9
-import com.reactnativenavigation.layout.LayoutFactory.ReactRootViewCreator;
10
 
9
 
11
 public class NavigationReactRootViewCreator implements ReactRootViewCreator {
10
 public class NavigationReactRootViewCreator implements ReactRootViewCreator {
12
 	@Override
11
 	@Override

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactRootViewCreator.java View File

1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Activity;
4
+import android.view.View;
5
+
6
+public interface ReactRootViewCreator {
7
+	View create(Activity activity, final String id, final String name);
8
+}

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/TestApplication.java View File

4
 import com.reactnativenavigation.controllers.CommandsHandler;
4
 import com.reactnativenavigation.controllers.CommandsHandler;
5
 import com.reactnativenavigation.mocks.TestDevPermissionRequest;
5
 import com.reactnativenavigation.mocks.TestDevPermissionRequest;
6
 import com.reactnativenavigation.mocks.TestReactNativeHost;
6
 import com.reactnativenavigation.mocks.TestReactNativeHost;
7
+import com.reactnativenavigation.react.NavigationReactRootViewCreator;
7
 
8
 
8
 public class TestApplication extends NavigationApplication {
9
 public class TestApplication extends NavigationApplication {
9
 
10
 
17
 		Config config = new Config();
18
 		Config config = new Config();
18
 		config.reactNativeHost = new TestReactNativeHost(this, isDebug());
19
 		config.reactNativeHost = new TestReactNativeHost(this, isDebug());
19
 		config.activityLifecycleDelegate = new ActivityLifecycleDelegate(config.reactNativeHost.getReactInstanceManager(), new TestDevPermissionRequest());
20
 		config.activityLifecycleDelegate = new ActivityLifecycleDelegate(config.reactNativeHost.getReactInstanceManager(), new TestDevPermissionRequest());
20
-		config.commandsHandler = new CommandsHandler();
21
+		config.commandsHandler = new CommandsHandler(new NavigationReactRootViewCreator());
21
 		return config;
22
 		return config;
22
 	}
23
 	}
23
 }
24
 }

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

2
 
2
 
3
 import com.reactnativenavigation.BaseTest;
3
 import com.reactnativenavigation.BaseTest;
4
 import com.reactnativenavigation.NavigationActivity;
4
 import com.reactnativenavigation.NavigationActivity;
5
+import com.reactnativenavigation.NavigationApplication;
5
 import com.reactnativenavigation.layout.Container;
6
 import com.reactnativenavigation.layout.Container;
6
 
7
 
7
 import org.json.JSONObject;
8
 import org.json.JSONObject;
14
 
15
 
15
 	@Test
16
 	@Test
16
 	public void setRootCreatesTheLayout_SetContentView() throws Exception {
17
 	public void setRootCreatesTheLayout_SetContentView() throws Exception {
17
-		CommandsHandler uut = new CommandsHandler();
18
+		CommandsHandler uut = NavigationApplication.instance.getConfig().commandsHandler;
18
 		JSONObject json = new JSONObject("{" +
19
 		JSONObject json = new JSONObject("{" +
19
 				"id: containerId123," +
20
 				"id: containerId123," +
20
 				"type: Container" +
21
 				"type: Container" +