|
@@ -7,9 +7,16 @@ import com.facebook.react.ReactRootView;
|
7
|
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
8
|
8
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
9
|
9
|
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+import com.facebook.react.bridge.ReadableArray;
|
10
|
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
11
|
13
|
import com.reactnativenavigation.controllers.NavigationActivity;
|
12
|
14
|
import com.reactnativenavigation.layout.LayoutFactory;
|
|
15
|
+import com.reactnativenavigation.layout.LayoutNode;
|
|
16
|
+
|
|
17
|
+import java.util.ArrayList;
|
|
18
|
+import java.util.HashMap;
|
|
19
|
+import java.util.Map;
|
13
|
20
|
|
14
|
21
|
public class NavigationModule extends ReactContextBaseJavaModule {
|
15
|
22
|
public static final String NAME = "RNNBridgeModule";
|
|
@@ -39,6 +46,10 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
39
|
46
|
}
|
40
|
47
|
});
|
41
|
48
|
|
|
49
|
+ final LayoutNode layoutTreeRoot = readableMapToLayoutNode(layoutTree);
|
|
50
|
+ final View rootView = factory.create(layoutTreeRoot);
|
|
51
|
+ NavigationActivity.instance.setContentView(rootView);
|
|
52
|
+
|
42
|
53
|
// Map<String, Object> node = new HashMap<String, Object>();
|
43
|
54
|
// node.put("id", container.getString("id"));
|
44
|
55
|
// HashMap<String, Object> data = new HashMap<>();
|
|
@@ -49,4 +60,39 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
49
|
60
|
}
|
50
|
61
|
});
|
51
|
62
|
}
|
|
63
|
+
|
|
64
|
+ private LayoutNode readableMapToLayoutNode(ReadableMap readableMap) {
|
|
65
|
+ final LayoutNode layoutNode = new LayoutNode();
|
|
66
|
+ layoutNode.id = readableMap.getString("id");
|
|
67
|
+ layoutNode.type = readableMap.getString("type");
|
|
68
|
+ layoutNode.data = readableMapToJavaMap(readableMap.getMap("data"));
|
|
69
|
+
|
|
70
|
+ ReadableArray childrenNodes = readableMap.getArray("children");
|
|
71
|
+ layoutNode.children = new ArrayList<>(childrenNodes.size());
|
|
72
|
+ for (int i = 0; i < childrenNodes.size(); i++) {
|
|
73
|
+ ReadableMap child = childrenNodes.getMap(i);
|
|
74
|
+ layoutNode.children.add(readableMapToLayoutNode(child));
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ return layoutNode;
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ private Map<String, Object> readableMapToJavaMap(ReadableMap readableMap) {
|
|
81
|
+ final Map<String, Object> map = new HashMap<>();
|
|
82
|
+ for (ReadableMapKeySetIterator it = readableMap.keySetIterator(); it.hasNextKey();) {
|
|
83
|
+ final String key = it.nextKey();
|
|
84
|
+ switch (readableMap.getType(key)) {
|
|
85
|
+ case String:
|
|
86
|
+ map.put(key, readableMap.getString(key));
|
|
87
|
+ break;
|
|
88
|
+ case Map:
|
|
89
|
+ map.put(key, readableMapToJavaMap(readableMap.getMap(key)));
|
|
90
|
+ break;
|
|
91
|
+ default:
|
|
92
|
+ throw new IllegalArgumentException("WTF?!");
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+ return map;
|
|
96
|
+ }
|
|
97
|
+
|
52
|
98
|
}
|