|
@@ -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
|
}
|