Browse Source

topTab params

Daniel Zlotin 8 years ago
parent
commit
ac6c0afa82

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenFactory.java View File

@@ -0,0 +1,15 @@
1
+package com.reactnativenavigation.layouts;
2
+
3
+import android.content.Context;
4
+
5
+import com.reactnativenavigation.params.ScreenParams;
6
+
7
+public class ScreenFactory {
8
+    public static Screen create(Context context, ScreenParams screenParams) {
9
+        if (screenParams.hasTopTabs()) {
10
+            throw new UnsupportedOperationException("Rotem do your magic here");
11
+        } else {
12
+            return new SingleScreen(context, screenParams);
13
+        }
14
+    }
15
+}

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java View File

@@ -31,7 +31,7 @@ public class ScreenStack extends FrameLayout {
31 31
     }
32 32
 
33 33
     private void addScreen(ScreenParams screenParams) {
34
-        Screen screen = new SingleScreen(getContext(), screenParams);
34
+        Screen screen = ScreenFactory.create(getContext(), screenParams);
35 35
         addView(screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
36 36
         stack.push(screen);
37 37
     }

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

@@ -13,6 +13,11 @@ public class ScreenParams {
13 13
     public String title;
14 14
     public ScreenStyleParams styleParams;
15 15
     public Bundle navigationParams;
16
+    public List<TopTabParams> topTabParams;
16 17
     //    public String tabLabel; TODO when tabs are supported move to TabParams
17 18
     //    public Drawable tabIcon;
19
+
20
+    public boolean hasTopTabs() {
21
+        return topTabParams != null && !topTabParams.isEmpty();
22
+    }
18 23
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java View File

@@ -0,0 +1,10 @@
1
+package com.reactnativenavigation.params;
2
+
3
+import android.os.Bundle;
4
+
5
+public class TopTabParams {
6
+    public String screenId;
7
+    public String title;
8
+    public String screenInstanceId;
9
+    public Bundle passProps;
10
+}

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

@@ -13,6 +13,7 @@ public class ScreenParamsParser extends Parser {
13 13
     private static final String KEY_NAVIGATION_PARAMS = "navigationParams";
14 14
     private static final String KEY_BUTTONS = "titleBarButtons";
15 15
     private static final String STYLE_PARAMS = "styleParams";
16
+    public static final String TOP_TABS = "topTabs";
16 17
 
17 18
     @SuppressWarnings("ConstantConditions")
18 19
     public static ScreenParams parse(Bundle params) {
@@ -26,6 +27,9 @@ public class ScreenParamsParser extends Parser {
26 27
         result.buttons = TitleBarButtonParamsParser.parse(params.getBundle(KEY_BUTTONS));
27 28
         result.title = params.getString(KEY_TITLE);
28 29
         result.styleParams = ScreenStyleParamsParser.parse(params.getBundle(STYLE_PARAMS));
30
+        if (hasKey(params, TOP_TABS)) {
31
+            result.topTabParams = TopTabParamsParser.parse(params.getBundle(TOP_TABS));
32
+        }
29 33
         return result;
30 34
     }
31 35
 }

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

@@ -0,0 +1,35 @@
1
+package com.reactnativenavigation.params.parsers;
2
+
3
+import android.os.Bundle;
4
+import android.support.annotation.NonNull;
5
+
6
+import com.reactnativenavigation.params.TopTabParams;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+
11
+public class TopTabParamsParser extends Parser {
12
+    private static final String KEY_SCREEN_ID = "screenId";
13
+    private static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
14
+    private static final String KEY_TITLE = "title";
15
+    private static final String KEY_PROPS = "passProps";
16
+
17
+    @SuppressWarnings("ConstantConditions")
18
+    public static List<TopTabParams> parse(Bundle params) {
19
+        List<TopTabParams> result = new ArrayList<>();
20
+        for (String key : params.keySet()) {
21
+            result.add(parseItem(params.getBundle(key)));
22
+        }
23
+        return result;
24
+    }
25
+
26
+    @NonNull
27
+    private static TopTabParams parseItem(Bundle params) {
28
+        TopTabParams result = new TopTabParams();
29
+        result.screenId = params.getString(KEY_SCREEN_ID);
30
+        result.screenInstanceId = params.getString(KEY_SCREEN_INSTANCE_ID);
31
+        result.title = params.getString(KEY_TITLE);
32
+        result.passProps = params.getBundle(KEY_PROPS);
33
+        return result;
34
+    }
35
+}