|
|
@@ -4,9 +4,6 @@ import android.os.Bundle;
|
|
4
|
4
|
import android.view.View;
|
|
5
|
5
|
|
|
6
|
6
|
import com.facebook.react.ReactRootView;
|
|
7
|
|
-import com.facebook.react.bridge.ReadableArray;
|
|
8
|
|
-import com.facebook.react.bridge.ReadableMap;
|
|
9
|
|
-import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
10
|
7
|
import com.reactnativenavigation.NavigationActivity;
|
|
11
|
8
|
import com.reactnativenavigation.NavigationApplication;
|
|
12
|
9
|
import com.reactnativenavigation.layout.LayoutFactory;
|
|
|
@@ -15,14 +12,11 @@ import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
|
|
15
|
12
|
import com.reactnativenavigation.layout.parse.LayoutNode;
|
|
16
|
13
|
import com.reactnativenavigation.utils.UiThread;
|
|
17
|
14
|
|
|
18
|
|
-import java.util.ArrayList;
|
|
19
|
|
-import java.util.HashMap;
|
|
20
|
|
-import java.util.List;
|
|
21
|
15
|
import java.util.Map;
|
|
22
|
16
|
|
|
23
|
17
|
public class CommandsHandler {
|
|
24
|
18
|
|
|
25
|
|
- public void setRoot(final NavigationActivity activity, final ReadableMap layoutTree) {
|
|
|
19
|
+ public void setRoot(final NavigationActivity activity, final Map<String, Object> layoutTree) {
|
|
26
|
20
|
LayoutFactory factory =
|
|
27
|
21
|
new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
|
|
28
|
22
|
@Override
|
|
|
@@ -35,12 +29,12 @@ public class CommandsHandler {
|
|
35
|
29
|
}
|
|
36
|
30
|
}, new BottomTabsCreator());
|
|
37
|
31
|
|
|
38
|
|
- final LayoutNode layoutTreeRoot = readableMapToLayoutNode(layoutTree);
|
|
|
32
|
+ final LayoutNode layoutTreeRoot = LayoutNode.fromTree(layoutTree);
|
|
39
|
33
|
final View rootView = factory.create(layoutTreeRoot);
|
|
40
|
34
|
activity.setContentView(rootView);
|
|
41
|
35
|
}
|
|
42
|
36
|
|
|
43
|
|
- public void push(final NavigationActivity activity, String onContainerId, final ReadableMap layout) {
|
|
|
37
|
+ public void push(final NavigationActivity activity, String onContainerId, final Map<String, Object> layoutTree) {
|
|
44
|
38
|
LayoutFactory factory =
|
|
45
|
39
|
new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
|
|
46
|
40
|
@Override
|
|
|
@@ -52,7 +46,7 @@ public class CommandsHandler {
|
|
52
|
46
|
return rootView;
|
|
53
|
47
|
}
|
|
54
|
48
|
}, new BottomTabsCreator());
|
|
55
|
|
- final LayoutNode layoutNode = readableMapToLayoutNode(layout);
|
|
|
49
|
+ final LayoutNode layoutNode = LayoutNode.fromTree(layoutTree);
|
|
56
|
50
|
final View rootView = factory.create(layoutNode);
|
|
57
|
51
|
((StackLayout) activity.getContentView()).push(rootView);
|
|
58
|
52
|
}
|
|
|
@@ -65,35 +59,4 @@ public class CommandsHandler {
|
|
65
|
59
|
}
|
|
66
|
60
|
});
|
|
67
|
61
|
}
|
|
68
|
|
-
|
|
69
|
|
- private LayoutNode readableMapToLayoutNode(ReadableMap readableMap) {
|
|
70
|
|
- String id = readableMap.getString("id");
|
|
71
|
|
- LayoutNode.Type type = LayoutNode.Type.fromString(readableMap.getString("type"));
|
|
72
|
|
- Map<String, Object> data = readableMapToJavaMap(readableMap.getMap("data"));
|
|
73
|
|
-
|
|
74
|
|
- ReadableArray childrenNodes = readableMap.getArray("children");
|
|
75
|
|
- List<LayoutNode> children = new ArrayList<>(childrenNodes.size());
|
|
76
|
|
- for (int i = 0; i < childrenNodes.size(); i++) {
|
|
77
|
|
- ReadableMap child = childrenNodes.getMap(i);
|
|
78
|
|
- children.add(readableMapToLayoutNode(child));
|
|
79
|
|
- }
|
|
80
|
|
-
|
|
81
|
|
- return new LayoutNode(id, type, data, children);
|
|
82
|
|
- }
|
|
83
|
|
-
|
|
84
|
|
- private Map<String, Object> readableMapToJavaMap(ReadableMap readableMap) {
|
|
85
|
|
- final Map<String, Object> map = new HashMap<>();
|
|
86
|
|
- for (ReadableMapKeySetIterator it = readableMap.keySetIterator(); it.hasNextKey(); ) {
|
|
87
|
|
- final String key = it.nextKey();
|
|
88
|
|
- switch (readableMap.getType(key)) {
|
|
89
|
|
- case String:
|
|
90
|
|
- map.put(key, readableMap.getString(key));
|
|
91
|
|
- break;
|
|
92
|
|
- case Map:
|
|
93
|
|
- map.put(key, readableMapToJavaMap(readableMap.getMap(key)));
|
|
94
|
|
- break;
|
|
95
|
|
- }
|
|
96
|
|
- }
|
|
97
|
|
- return map;
|
|
98
|
|
- }
|
|
99
|
62
|
}
|