Explorar el Código

refactor - remove CommandsHandler

Daniel Zlotin hace 7 años
padre
commit
2e76dfad04

+ 0
- 2
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java Ver fichero

@@ -3,12 +3,10 @@ package com.reactnativenavigation.e2e.androide2e;
3 3
 import android.support.test.uiautomator.By;
4 4
 
5 5
 import org.junit.FixMethodOrder;
6
-import org.junit.Ignore;
7 6
 import org.junit.Test;
8 7
 import org.junit.runners.MethodSorters;
9 8
 
10 9
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
11
-@Ignore
12 10
 public class ApplicationLifecycleTest extends BaseTest {
13 11
 
14 12
 	@Test

+ 1
- 3
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Ver fichero

@@ -6,7 +6,6 @@ import com.facebook.react.ReactApplication;
6 6
 import com.facebook.react.ReactInstanceManager;
7 7
 import com.facebook.react.ReactNativeHost;
8 8
 import com.reactnativenavigation.controllers.ActivityLifecycleDelegate;
9
-import com.reactnativenavigation.controllers.CommandsHandler;
10 9
 import com.reactnativenavigation.react.DevPermissionRequest;
11 10
 import com.reactnativenavigation.react.NavigationReactNativeHost;
12 11
 
@@ -18,8 +17,7 @@ public abstract class NavigationApplication extends Application implements React
18 17
 	@Override
19 18
 	public void onCreate() {
20 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 22
 		ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
25 23
 		DevPermissionRequest devPermissionRequest = new DevPermissionRequest(this, isDebug());

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

@@ -1,39 +0,0 @@
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 Ver fichero

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

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

@@ -1,20 +1,26 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
+import android.view.View;
4
+
5
+import com.facebook.react.ReactInstanceManager;
3 6
 import com.facebook.react.bridge.ReactApplicationContext;
4 7
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5 8
 import com.facebook.react.bridge.ReactMethod;
6 9
 import com.facebook.react.bridge.ReadableMap;
7 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 15
 import com.reactnativenavigation.utils.UiThread;
10 16
 
11 17
 public class NavigationModule extends ReactContextBaseJavaModule {
12 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 22
 		super(reactContext);
17
-		this.commandsHandler = commandsHandler;
23
+		this.reactInstanceManager = reactInstanceManager;
18 24
 	}
19 25
 
20 26
 	@Override
@@ -27,7 +33,10 @@ public class NavigationModule extends ReactContextBaseJavaModule {
27 33
 		handle(new Runnable() {
28 34
 			@Override
29 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,7 +46,10 @@ public class NavigationModule extends ReactContextBaseJavaModule {
37 46
 		handle(new Runnable() {
38 47
 			@Override
39 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,7 +59,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
47 59
 		handle(new Runnable() {
48 60
 			@Override
49 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 Ver fichero

@@ -1,11 +1,11 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
+import com.facebook.react.ReactNativeHost;
3 4
 import com.facebook.react.ReactPackage;
4 5
 import com.facebook.react.bridge.JavaScriptModule;
5 6
 import com.facebook.react.bridge.NativeModule;
6 7
 import com.facebook.react.bridge.ReactApplicationContext;
7 8
 import com.facebook.react.uimanager.ViewManager;
8
-import com.reactnativenavigation.controllers.CommandsHandler;
9 9
 
10 10
 import java.util.Arrays;
11 11
 import java.util.Collections;
@@ -13,16 +13,16 @@ import java.util.List;
13 13
 
14 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 22
 	@Override
23 23
 	public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
24 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 Ver fichero

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