Browse Source

Clean up LayoutFactory

Guy Carmeli 6 years ago
parent
commit
dfa5480be2

+ 24
- 22
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

63
 	}
63
 	}
64
 
64
 
65
     private ViewController createSideMenuRoot(LayoutNode node) {
65
     private ViewController createSideMenuRoot(LayoutNode node) {
66
-        final Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
67
-		SideMenuController sideMenuLayout = new SideMenuController(activity, node.id, options);
66
+        SideMenuController sideMenuLayout = new SideMenuController(activity, node.id, getOptions(node));
68
 		for (LayoutNode child : node.children) {
67
 		for (LayoutNode child : node.children) {
69
 			ViewController childLayout = create(child);
68
 			ViewController childLayout = create(child);
70
 			switch (child.type) {
69
 			switch (child.type) {
99
 	private ViewController createComponent(LayoutNode node) {
98
 	private ViewController createComponent(LayoutNode node) {
100
 		String id = node.id;
99
 		String id = node.id;
101
 		String name = node.data.optString("name");
100
 		String name = node.data.optString("name");
102
-		Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
103
-		return new ComponentViewController(activity,
101
+        return new ComponentViewController(activity,
104
                 id,
102
                 id,
105
                 name,
103
                 name,
106
                 new ComponentViewCreator(reactInstanceManager),
104
                 new ComponentViewCreator(reactInstanceManager),
107
-                options
105
+                getOptions(node)
108
         );
106
         );
109
 	}
107
 	}
110
 
108
 
111
     private ViewController createExternalComponent(LayoutNode node) {
109
     private ViewController createExternalComponent(LayoutNode node) {
112
-        final Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
113
-        ExternalComponent externalComponent = ExternalComponent.parse(node.data);
110
+        final ExternalComponent externalComponent = ExternalComponent.parse(node.data);
114
         return new ExternalComponentViewController(activity,
111
         return new ExternalComponentViewController(activity,
115
                 node.id,
112
                 node.id,
116
                 externalComponent,
113
                 externalComponent,
117
                 externalComponentCreators.get(externalComponent.name.get()),
114
                 externalComponentCreators.get(externalComponent.name.get()),
118
-                options
115
+                getOptions(node)
119
         );
116
         );
120
     }
117
     }
121
 
118
 
122
 	private ViewController createStack(LayoutNode node) {
119
 	private ViewController createStack(LayoutNode node) {
123
-        final Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
124
-		StackController stackController = new StackController(activity, node.id, options);
125
-        for (int i = 0; i < node.children.size(); i++) {
126
-            if (i < node.children.size() - 1) {
127
-                stackController.push(create(node.children.get(i)), new NoOpPromise());
120
+        StackController stackController = new StackController(activity, node.id, getOptions(node));
121
+        addChildrenToStack(node.children, stackController);
122
+        return stackController;
123
+	}
124
+
125
+    private void addChildrenToStack(List<LayoutNode> children, StackController stackController) {
126
+        for (int i = 0; i < children.size(); i++) {
127
+            if (i < children.size() - 1) {
128
+                stackController.push(create(children.get(i)), new NoOpPromise());
128
             } else {
129
             } else {
129
-                stackController.animatePush(create(node.children.get(i)), new NoOpPromise());
130
+                stackController.animatePush(create(children.get(i)), new NoOpPromise());
130
             }
131
             }
131
         }
132
         }
132
-		return stackController;
133
-	}
133
+    }
134
 
134
 
135
-	private ViewController createBottomTabs(LayoutNode node) {
136
-        final Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
137
-		final BottomTabsController tabsComponent = new BottomTabsController(activity, new ImageLoader(), node.id, options);
135
+    private ViewController createBottomTabs(LayoutNode node) {
136
+        final BottomTabsController tabsComponent = new BottomTabsController(activity, new ImageLoader(), node.id, getOptions(node));
138
 		List<ViewController> tabs = new ArrayList<>();
137
 		List<ViewController> tabs = new ArrayList<>();
139
 		for (int i = 0; i < node.children.size(); i++) {
138
 		for (int i = 0; i < node.children.size(); i++) {
140
             tabs.add(create(node.children.get(i)));
139
             tabs.add(create(node.children.get(i)));
147
         final List<ViewController> tabs = new ArrayList<>();
146
         final List<ViewController> tabs = new ArrayList<>();
148
         for (int i = 0; i < node.children.size(); i++) {
147
         for (int i = 0; i < node.children.size(); i++) {
149
             ViewController tabController = create(node.children.get(i));
148
             ViewController tabController = create(node.children.get(i));
150
-            Options options = Options.parse(typefaceManager, node.children.get(i).getNavigationOptions(), defaultOptions);
149
+            Options options = getOptions(node.children.get(i));
151
             options.setTopTabIndex(i);
150
             options.setTopTabIndex(i);
152
             tabs.add(tabController);
151
             tabs.add(tabController);
153
         }
152
         }
154
-        Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
155
-        return new TopTabsController(activity, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), options);
153
+        return new TopTabsController(activity, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), getOptions(node));
154
+    }
155
+
156
+    private Options getOptions(LayoutNode node) {
157
+        return Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
156
     }
158
     }
157
 }
159
 }