Procházet zdrojové kódy

Clean up LayoutFactory

Guy Carmeli před 6 roky
rodič
revize
dfa5480be2

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

@@ -63,8 +63,7 @@ public class LayoutFactory {
63 63
 	}
64 64
 
65 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 67
 		for (LayoutNode child : node.children) {
69 68
 			ViewController childLayout = create(child);
70 69
 			switch (child.type) {
@@ -99,42 +98,42 @@ public class LayoutFactory {
99 98
 	private ViewController createComponent(LayoutNode node) {
100 99
 		String id = node.id;
101 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 102
                 id,
105 103
                 name,
106 104
                 new ComponentViewCreator(reactInstanceManager),
107
-                options
105
+                getOptions(node)
108 106
         );
109 107
 	}
110 108
 
111 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 111
         return new ExternalComponentViewController(activity,
115 112
                 node.id,
116 113
                 externalComponent,
117 114
                 externalComponentCreators.get(externalComponent.name.get()),
118
-                options
115
+                getOptions(node)
119 116
         );
120 117
     }
121 118
 
122 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 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 137
 		List<ViewController> tabs = new ArrayList<>();
139 138
 		for (int i = 0; i < node.children.size(); i++) {
140 139
             tabs.add(create(node.children.get(i)));
@@ -147,11 +146,14 @@ public class LayoutFactory {
147 146
         final List<ViewController> tabs = new ArrayList<>();
148 147
         for (int i = 0; i < node.children.size(); i++) {
149 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 150
             options.setTopTabIndex(i);
152 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
 }