Browse Source

LayoutFactory

Daniel Zlotin 8 years ago
parent
commit
9ef726853e

+ 2
- 3
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -10,7 +10,7 @@ import android.view.View;
10 10
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
11 11
 import com.reactnativenavigation.NavigationApplication;
12 12
 import com.reactnativenavigation.layouts.Layout;
13
-import com.reactnativenavigation.layouts.SingleScreenLayout;
13
+import com.reactnativenavigation.layouts.LayoutFactory;
14 14
 import com.reactnativenavigation.params.ActivityParams;
15 15
 import com.reactnativenavigation.params.parsers.ActivityParamsParser;
16 16
 import com.reactnativenavigation.react.JsDevReloadHandler;
@@ -45,8 +45,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
45 45
     }
46 46
 
47 47
     private void createLayout() {
48
-        //TODO layout factory (tabsLayout etc)
49
-        layout = new SingleScreenLayout(this, activityParams.screenParams);
48
+        layout = LayoutFactory.create(this, activityParams);
50 49
         setContentView((View) layout);
51 50
     }
52 51
 

+ 51
- 66
android/app/src/main/java/com/reactnativenavigation/layouts/LayoutFactory.java View File

@@ -1,76 +1,61 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3 3
 import android.app.Activity;
4
-import android.support.v4.widget.DrawerLayout;
5
-import android.view.Gravity;
6
-import android.widget.FrameLayout;
7
-import android.widget.LinearLayout;
8 4
 
9
-import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
10
-
11
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
12
-import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
5
+import com.reactnativenavigation.params.ActivityParams;
13 6
 
14 7
 public class LayoutFactory {
15
-    public static class SideMenuParams {
16
-        private boolean enabled = false;
17
-    }
18
-
19
-    public static class BottomTabsParams {
20
-        private boolean enabled = false;
21
-    }
22
-
23
-    public static class Params {
24
-        private SideMenuParams sideMenu = new SideMenuParams();
25
-        private BottomTabsParams bottomTabs = new BottomTabsParams();
26
-    }
27
-
28
-    public static Layout create(Activity activity, Params params) {
29
-        LinearLayout root = createRoot(activity);
30
-        FrameLayout content = createContent(activity);
31
-        addContentWithMenuIfNeeded(activity, params, root, content);
32
-        addBottomTabsIfNeeded(activity, params, root);
33
-
34
-        return null;
35
-    }
36
-
37
-    private static void addBottomTabsIfNeeded(Activity activity, Params params, LinearLayout root) {
38
-        if (params.bottomTabs.enabled) {
39
-            AHBottomNavigation bottomTabs = createBottomTabs(activity);
40
-            root.addView(bottomTabs, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
8
+    public static Layout create(Activity activity, ActivityParams params) {
9
+        switch (params.type) {
10
+            case TabBased:
11
+                throw new UnsupportedOperationException("WHAT!? u crazy...");
12
+            case SingleScreen:
13
+            default:
14
+                return createSingleScreenLayout(activity, params);
41 15
         }
42 16
     }
43 17
 
44
-    private static void addContentWithMenuIfNeeded(Activity activity, Params params, LinearLayout root, FrameLayout content) {
45
-        if (params.sideMenu.enabled) {
46
-            DrawerLayout sideMenu = createSideMenu(activity, content);
47
-            root.addView(sideMenu, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1));
48
-        } else {
49
-            root.addView(content, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1));
50
-        }
51
-    }
52
-
53
-    private static AHBottomNavigation createBottomTabs(Activity activity) {
54
-        return new AHBottomNavigation(activity);
55
-    }
56
-
57
-    private static LinearLayout createRoot(Activity activity) {
58
-        LinearLayout root = new LinearLayout(activity);
59
-        root.setOrientation(LinearLayout.VERTICAL);
60
-        return root;
61
-    }
62
-
63
-    private static DrawerLayout createSideMenu(Activity activity, FrameLayout content) {
64
-        DrawerLayout drawerLayout = new DrawerLayout(activity);
65
-        FrameLayout drawerContent = new FrameLayout(activity);
66
-        drawerLayout.addView(content, new DrawerLayout.LayoutParams(MATCH_PARENT, 0, 1));
67
-        DrawerLayout.LayoutParams drawerContentParams = new DrawerLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT);
68
-        drawerContentParams.gravity = Gravity.START;
69
-        drawerLayout.addView(drawerContent, drawerContentParams);
70
-        return drawerLayout;
71
-    }
72
-
73
-    private static FrameLayout createContent(Activity activity) {
74
-        return new FrameLayout(activity);
75
-    }
18
+    private static Layout createSingleScreenLayout(Activity activity, ActivityParams params) {
19
+        return new SingleScreenLayout(activity, params.screenParams);
20
+    }
21
+
22
+//    private static void addBottomTabsIfNeeded(Activity activity, Params params, LinearLayout root) {
23
+//        if (params.bottomTabs.enabled) {
24
+//            AHBottomNavigation bottomTabs = createBottomTabs(activity);
25
+//            root.addView(bottomTabs, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
26
+//        }
27
+//    }
28
+//
29
+//    private static void addContentWithMenuIfNeeded(Activity activity, Params params, LinearLayout root, FrameLayout content) {
30
+//        if (params.sideMenu.enabled) {
31
+//            DrawerLayout sideMenu = createSideMenu(activity, content);
32
+//            root.addView(sideMenu, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1));
33
+//        } else {
34
+//            root.addView(content, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1));
35
+//        }
36
+//    }
37
+//
38
+//    private static AHBottomNavigation createBottomTabs(Activity activity) {
39
+//        return new AHBottomNavigation(activity);
40
+//    }
41
+//
42
+//    private static LinearLayout createRoot(Activity activity) {
43
+//        LinearLayout root = new LinearLayout(activity);
44
+//        root.setOrientation(LinearLayout.VERTICAL);
45
+//        return root;
46
+//    }
47
+//
48
+//    private static DrawerLayout createSideMenu(Activity activity, FrameLayout content) {
49
+//        DrawerLayout drawerLayout = new DrawerLayout(activity);
50
+//        FrameLayout drawerContent = new FrameLayout(activity);
51
+//        drawerLayout.addView(content, new DrawerLayout.LayoutParams(MATCH_PARENT, 0, 1));
52
+//        DrawerLayout.LayoutParams drawerContentParams = new DrawerLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT);
53
+//        drawerContentParams.gravity = Gravity.START;
54
+//        drawerLayout.addView(drawerContent, drawerContentParams);
55
+//        return drawerLayout;
56
+//    }
57
+//
58
+//    private static FrameLayout createContent(Activity activity) {
59
+//        return new FrameLayout(activity);
60
+//    }
76 61
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/ActivityParams.java View File

@@ -1,5 +1,10 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3 3
 public class ActivityParams {
4
+    public enum Type {
5
+        SingleScreen, TabBased
6
+    }
7
+
8
+    public Type type;
4 9
     public ScreenParams screenParams;
5 10
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/ActivityParamsParser.java View File

@@ -7,6 +7,7 @@ import com.reactnativenavigation.params.ActivityParams;
7 7
 public class ActivityParamsParser {
8 8
     public static ActivityParams parse(Bundle params) {
9 9
         ActivityParams result = new ActivityParams();
10
+        result.type = ActivityParams.Type.SingleScreen; //TODO tabs
10 11
         result.screenParams = ScreenParamsParser.parse(params.getBundle("screen"));
11 12
         return result;
12 13
     }