Browse Source

refactor - remove CommandsHandler

Daniel Zlotin 7 years ago
parent
commit
2e76dfad04

+ 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
- 3
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

6
 import com.facebook.react.ReactInstanceManager;
6
 import com.facebook.react.ReactInstanceManager;
7
 import com.facebook.react.ReactNativeHost;
7
 import com.facebook.react.ReactNativeHost;
8
 import com.reactnativenavigation.controllers.ActivityLifecycleDelegate;
8
 import com.reactnativenavigation.controllers.ActivityLifecycleDelegate;
9
-import com.reactnativenavigation.controllers.CommandsHandler;
10
 import com.reactnativenavigation.react.DevPermissionRequest;
9
 import com.reactnativenavigation.react.DevPermissionRequest;
11
 import com.reactnativenavigation.react.NavigationReactNativeHost;
10
 import com.reactnativenavigation.react.NavigationReactNativeHost;
12
 
11
 
18
 	@Override
17
 	@Override
19
 	public void onCreate() {
18
 	public void onCreate() {
20
 		super.onCreate();
19
 		super.onCreate();
21
-		CommandsHandler commandsHandler = new CommandsHandler(this);
22
-		reactNativeHost = new NavigationReactNativeHost(this, isDebug(), commandsHandler);
20
+		reactNativeHost = new NavigationReactNativeHost(this, isDebug());
23
 
21
 
24
 		ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
22
 		ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
25
 		DevPermissionRequest devPermissionRequest = new DevPermissionRequest(this, isDebug());
23
 		DevPermissionRequest devPermissionRequest = new DevPermissionRequest(this, isDebug());

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

1
-package com.reactnativenavigation.controllers;
2
-
3
-import android.view.View;
4
-
5
-import com.reactnativenavigation.NavigationActivity;
6
-import com.reactnativenavigation.NavigationApplication;
7
-import com.reactnativenavigation.layout.LayoutFactory;
8
-import com.reactnativenavigation.layout.LayoutNode;
9
-import com.reactnativenavigation.layout.StackLayout;
10
-import com.reactnativenavigation.layout.containers.Container;
11
-
12
-import org.json.JSONObject;
13
-
14
-public class CommandsHandler {
15
-
16
-	private final NavigationApplication application;
17
-
18
-	public CommandsHandler(NavigationApplication application) {
19
-		this.application = application;
20
-	}
21
-
22
-	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
23
-		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
24
-		LayoutFactory factory = new LayoutFactory(activity, application.getReactNativeHost());
25
-		final View rootView = factory.create(layoutTreeRoot);
26
-		activity.setContentView(rootView);
27
-	}
28
-
29
-	public void push(final NavigationActivity activity, String onContainerId, JSONObject layoutTree) {
30
-		final LayoutNode layoutNode = LayoutNode.parse(layoutTree);
31
-		LayoutFactory factory = new LayoutFactory(activity, application.getReactNativeHost());
32
-		final View rootView = factory.create(layoutNode);
33
-		((StackLayout) activity.getContentView()).push((Container) rootView);
34
-	}
35
-
36
-	public void pop(final NavigationActivity activity, String onContainerId) {
37
-		((StackLayout) activity.getContentView()).pop();
38
-	}
39
-}

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

6
 import android.view.View;
6
 import android.view.View;
7
 import android.view.ViewGroup.LayoutParams;
7
 import android.view.ViewGroup.LayoutParams;
8
 
8
 
9
-import com.facebook.react.ReactNativeHost;
9
+import com.facebook.react.ReactInstanceManager;
10
 import com.reactnativenavigation.layout.containers.BottomTabs;
10
 import com.reactnativenavigation.layout.containers.BottomTabs;
11
 import com.reactnativenavigation.layout.containers.BottomTabsLayout;
11
 import com.reactnativenavigation.layout.containers.BottomTabsLayout;
12
 import com.reactnativenavigation.layout.containers.Container;
12
 import com.reactnativenavigation.layout.containers.Container;
17
 public class LayoutFactory {
17
 public class LayoutFactory {
18
 
18
 
19
 	private final Activity activity;
19
 	private final Activity activity;
20
-	private ReactNativeHost reactNativeHost;
20
+	private ReactInstanceManager reactInstanceManager;
21
 
21
 
22
-	public LayoutFactory(Activity activity, ReactNativeHost reactNativeHost) {
22
+	public LayoutFactory(Activity activity, final ReactInstanceManager reactInstanceManager) {
23
 		this.activity = activity;
23
 		this.activity = activity;
24
-		this.reactNativeHost = reactNativeHost;
24
+		this.reactInstanceManager = reactInstanceManager;
25
 	}
25
 	}
26
 
26
 
27
 	public View create(LayoutNode node) {
27
 	public View create(LayoutNode node) {
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, node.id, name, reactNativeHost.getReactInstanceManager());
80
+		Container container = new Container(activity, node.id, name, reactInstanceManager);
81
 		container.setId(CompatUtils.generateViewId());
81
 		container.setId(CompatUtils.generateViewId());
82
 		return container;
82
 		return container;
83
 
83
 

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

1
 package com.reactnativenavigation.react;
1
 package com.reactnativenavigation.react;
2
 
2
 
3
+import android.view.View;
4
+
5
+import com.facebook.react.ReactInstanceManager;
3
 import com.facebook.react.bridge.ReactApplicationContext;
6
 import com.facebook.react.bridge.ReactApplicationContext;
4
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
7
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
 import com.facebook.react.bridge.ReactMethod;
8
 import com.facebook.react.bridge.ReactMethod;
6
 import com.facebook.react.bridge.ReadableMap;
9
 import com.facebook.react.bridge.ReadableMap;
7
 import com.reactnativenavigation.NavigationActivity;
10
 import com.reactnativenavigation.NavigationActivity;
8
-import com.reactnativenavigation.controllers.CommandsHandler;
11
+import com.reactnativenavigation.layout.LayoutFactory;
12
+import com.reactnativenavigation.layout.LayoutNode;
13
+import com.reactnativenavigation.layout.StackLayout;
14
+import com.reactnativenavigation.layout.containers.Container;
9
 import com.reactnativenavigation.utils.UiThread;
15
 import com.reactnativenavigation.utils.UiThread;
10
 
16
 
11
 public class NavigationModule extends ReactContextBaseJavaModule {
17
 public class NavigationModule extends ReactContextBaseJavaModule {
12
 	private static final String NAME = "RNNBridgeModule";
18
 	private static final String NAME = "RNNBridgeModule";
13
-	private CommandsHandler commandsHandler;
19
+	private ReactInstanceManager reactInstanceManager;
14
 
20
 
15
-	public NavigationModule(final ReactApplicationContext reactContext, CommandsHandler commandsHandler) {
21
+	public NavigationModule(final ReactApplicationContext reactContext, final ReactInstanceManager reactInstanceManager) {
16
 		super(reactContext);
22
 		super(reactContext);
17
-		this.commandsHandler = commandsHandler;
23
+		this.reactInstanceManager = reactInstanceManager;
18
 	}
24
 	}
19
 
25
 
20
 	@Override
26
 	@Override
27
 		handle(new Runnable() {
33
 		handle(new Runnable() {
28
 			@Override
34
 			@Override
29
 			public void run() {
35
 			public void run() {
30
-				commandsHandler.setRoot(activity(), ArgsParser.parse(layoutTree));
36
+				final LayoutNode layoutTreeRoot = LayoutNode.parse(ArgsParser.parse(layoutTree));
37
+				LayoutFactory factory = new LayoutFactory(activity(), reactInstanceManager);
38
+				final View rootView = factory.create(layoutTreeRoot);
39
+				activity().setContentView(rootView);
31
 			}
40
 			}
32
 		});
41
 		});
33
 	}
42
 	}
37
 		handle(new Runnable() {
46
 		handle(new Runnable() {
38
 			@Override
47
 			@Override
39
 			public void run() {
48
 			public void run() {
40
-				commandsHandler.push(activity(), onContainerId, ArgsParser.parse(layoutTree));
49
+				final LayoutNode layoutNode = LayoutNode.parse(ArgsParser.parse(layoutTree));
50
+				LayoutFactory factory = new LayoutFactory(activity(), reactInstanceManager);
51
+				final View rootView = factory.create(layoutNode);
52
+				((StackLayout) activity().getContentView()).push((Container) rootView);
41
 			}
53
 			}
42
 		});
54
 		});
43
 	}
55
 	}
47
 		handle(new Runnable() {
59
 		handle(new Runnable() {
48
 			@Override
60
 			@Override
49
 			public void run() {
61
 			public void run() {
50
-				commandsHandler.pop(activity(), onContainerId);
62
+				((StackLayout) activity().getContentView()).pop();
51
 			}
63
 			}
52
 		});
64
 		});
53
 	}
65
 	}

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationPackage.java View File

1
 package com.reactnativenavigation.react;
1
 package com.reactnativenavigation.react;
2
 
2
 
3
+import com.facebook.react.ReactNativeHost;
3
 import com.facebook.react.ReactPackage;
4
 import com.facebook.react.ReactPackage;
4
 import com.facebook.react.bridge.JavaScriptModule;
5
 import com.facebook.react.bridge.JavaScriptModule;
5
 import com.facebook.react.bridge.NativeModule;
6
 import com.facebook.react.bridge.NativeModule;
6
 import com.facebook.react.bridge.ReactApplicationContext;
7
 import com.facebook.react.bridge.ReactApplicationContext;
7
 import com.facebook.react.uimanager.ViewManager;
8
 import com.facebook.react.uimanager.ViewManager;
8
-import com.reactnativenavigation.controllers.CommandsHandler;
9
 
9
 
10
 import java.util.Arrays;
10
 import java.util.Arrays;
11
 import java.util.Collections;
11
 import java.util.Collections;
13
 
13
 
14
 public class NavigationPackage implements ReactPackage {
14
 public class NavigationPackage implements ReactPackage {
15
 
15
 
16
-	private CommandsHandler commandsHandler;
16
+	private ReactNativeHost reactNativeHost;
17
 
17
 
18
-	public NavigationPackage(final CommandsHandler commandsHandler) {
19
-		this.commandsHandler = commandsHandler;
18
+	public NavigationPackage(final ReactNativeHost reactNativeHost) {
19
+		this.reactNativeHost = reactNativeHost;
20
 	}
20
 	}
21
 
21
 
22
 	@Override
22
 	@Override
23
 	public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
23
 	public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
24
 		return Arrays.<NativeModule>asList(
24
 		return Arrays.<NativeModule>asList(
25
-				new NavigationModule(reactContext, commandsHandler)
25
+				new NavigationModule(reactContext, reactNativeHost.getReactInstanceManager())
26
 		);
26
 		);
27
 	}
27
 	}
28
 
28
 

+ 2
- 5
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactNativeHost.java View File

5
 import com.facebook.react.ReactNativeHost;
5
 import com.facebook.react.ReactNativeHost;
6
 import com.facebook.react.ReactPackage;
6
 import com.facebook.react.ReactPackage;
7
 import com.facebook.react.shell.MainReactPackage;
7
 import com.facebook.react.shell.MainReactPackage;
8
-import com.reactnativenavigation.controllers.CommandsHandler;
9
 
8
 
10
 import java.util.Arrays;
9
 import java.util.Arrays;
11
 import java.util.List;
10
 import java.util.List;
13
 public class NavigationReactNativeHost extends ReactNativeHost {
12
 public class NavigationReactNativeHost extends ReactNativeHost {
14
 
13
 
15
 	private final boolean isDebug;
14
 	private final boolean isDebug;
16
-	private CommandsHandler commandsHandler;
17
 
15
 
18
-	public NavigationReactNativeHost(Application application, boolean isDebug, CommandsHandler commandsHandler) {
16
+	public NavigationReactNativeHost(Application application, boolean isDebug) {
19
 		super(application);
17
 		super(application);
20
 		this.isDebug = isDebug;
18
 		this.isDebug = isDebug;
21
-		this.commandsHandler = commandsHandler;
22
 	}
19
 	}
23
 
20
 
24
 	@Override
21
 	@Override
30
 	protected List<ReactPackage> getPackages() {
27
 	protected List<ReactPackage> getPackages() {
31
 		return Arrays.<ReactPackage>asList(
28
 		return Arrays.<ReactPackage>asList(
32
 				new MainReactPackage(),
29
 				new MainReactPackage(),
33
-				new NavigationPackage(commandsHandler)
30
+				new NavigationPackage(this)
34
 		);
31
 		);
35
 	}
32
 	}
36
 }
33
 }