|
@@ -1,8 +1,12 @@
|
1
|
1
|
package com.reactnativenavigation.params.parsers;
|
2
|
2
|
|
|
3
|
+import android.graphics.drawable.Drawable;
|
3
|
4
|
import android.os.Bundle;
|
4
|
5
|
|
5
|
6
|
import com.reactnativenavigation.params.ScreenParams;
|
|
7
|
+import com.reactnativenavigation.params.TitleBarButtonParams;
|
|
8
|
+import com.reactnativenavigation.params.TitleBarLeftButtonParams;
|
|
9
|
+import com.reactnativenavigation.params.TopTabParams;
|
6
|
10
|
import com.reactnativenavigation.react.ImageLoader;
|
7
|
11
|
|
8
|
12
|
import java.util.ArrayList;
|
|
@@ -16,6 +20,7 @@ public class ScreenParamsParser extends Parser {
|
16
|
20
|
private static final String KEY_NAVIGATION_PARAMS = "navigationParams";
|
17
|
21
|
private static final String KEY_RIGHT_BUTTONS = "rightButtons";
|
18
|
22
|
private static final String KEY_LEFT_BUTTON = "leftButton";
|
|
23
|
+ private static final String KEY_BACK_BUTTON_HIDDEN = "backButtonHidden";
|
19
|
24
|
private static final String STYLE_PARAMS = "styleParams";
|
20
|
25
|
private static final String TOP_TABS = "topTabs";
|
21
|
26
|
private static final String FRAGMENT_CREATOR_CLASS_NAME = "fragmentCreatorClassName";
|
|
@@ -30,29 +35,71 @@ public class ScreenParamsParser extends Parser {
|
30
|
35
|
result.navigationParams = params.getBundle(KEY_NAVIGATION_PARAMS);
|
31
|
36
|
result.navigatorEventId = result.navigationParams.getString(KEY_NAVIGATOR_EVENT_ID);
|
32
|
37
|
result.screenInstanceId = result.navigationParams.getString(KEY_SCREEN_INSTANCE_ID);
|
33
|
|
- if (hasKey(params, KEY_RIGHT_BUTTONS)) {
|
34
|
|
- result.rightButtons = new TitleBarButtonParamsParser().parseButtons(params.getBundle(KEY_RIGHT_BUTTONS));
|
35
|
|
- }
|
36
|
|
- if (hasKey(params, KEY_LEFT_BUTTON)) {
|
37
|
|
- result.leftButton = new TitleBarLeftButtonParamsParser().parseSingleButton(params.getBundle(KEY_LEFT_BUTTON));
|
38
|
|
- }
|
39
|
|
- result.title = params.getString(KEY_TITLE);
|
|
38
|
+
|
40
|
39
|
result.styleParams = new StyleParamsParser(params.getBundle(STYLE_PARAMS)).parse();
|
41
|
|
- if (hasKey(params, TOP_TABS)) {
|
42
|
|
- result.topTabParams = TopTabParamsParser.parse(params.getBundle(TOP_TABS));
|
43
|
|
- }
|
|
40
|
+
|
|
41
|
+ result.title = params.getString(KEY_TITLE);
|
|
42
|
+ result.rightButtons = parseRightButton(params);
|
|
43
|
+ result.leftButton = parseLeftButton(params);
|
|
44
|
+
|
|
45
|
+ result.topTabParams = parseTopTabs(params);
|
|
46
|
+
|
44
|
47
|
if (hasKey(params, FRAGMENT_CREATOR_CLASS_NAME)) {
|
45
|
48
|
result.fragmentCreatorClassName = params.getString(FRAGMENT_CREATOR_CLASS_NAME);
|
46
|
49
|
result.fragmentCreatorPassProps = params.getBundle(FRAGMENT_CREATOR_PASS_PROPS);
|
47
|
50
|
}
|
|
51
|
+
|
|
52
|
+ result.tabLabel = getTabLabel(params);
|
|
53
|
+ result.tabIcon = getTabIcon(params);
|
|
54
|
+
|
|
55
|
+ result.animateScreenTransitions = params.getBoolean("animated", true);
|
|
56
|
+
|
|
57
|
+ return result;
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ private static Drawable getTabIcon(Bundle params) {
|
|
61
|
+ Drawable tabIcon = null;
|
|
62
|
+ if (hasKey(params, "icon")) {
|
|
63
|
+ tabIcon = ImageLoader.loadImage(params.getString("icon"));
|
|
64
|
+ }
|
|
65
|
+ return tabIcon;
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ private static String getTabLabel(Bundle params) {
|
|
69
|
+ String tabLabel = null;
|
48
|
70
|
if (hasKey(params, "label")) {
|
49
|
|
- result.tabLabel = params.getString("label");
|
|
71
|
+ tabLabel = params.getString("label");
|
50
|
72
|
}
|
51
|
|
- if (hasKey(params, "icon")) {
|
52
|
|
- result.tabIcon = ImageLoader.loadImage(params.getString("icon"));
|
|
73
|
+ return tabLabel;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ private static List<TopTabParams> parseTopTabs(Bundle params) {
|
|
77
|
+ List<TopTabParams> topTabParams = null;
|
|
78
|
+ if (hasKey(params, TOP_TABS)) {
|
|
79
|
+ topTabParams = TopTabParamsParser.parse(params.getBundle(TOP_TABS));
|
53
|
80
|
}
|
54
|
|
- result.animateScreenTransitions = params.getBoolean("animated", true);
|
55
|
|
- return result;
|
|
81
|
+ return topTabParams;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ private static List<TitleBarButtonParams> parseRightButton(Bundle params) {
|
|
85
|
+ List<TitleBarButtonParams> rightButtons = null;
|
|
86
|
+ if (hasKey(params, KEY_RIGHT_BUTTONS)) {
|
|
87
|
+ rightButtons = new TitleBarButtonParamsParser().parseButtons(params.getBundle(KEY_RIGHT_BUTTONS));
|
|
88
|
+ }
|
|
89
|
+ return rightButtons;
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ private static TitleBarLeftButtonParams parseLeftButton(Bundle params) {
|
|
93
|
+ TitleBarLeftButtonParams leftButton = null;
|
|
94
|
+ if (hasKey(params, KEY_LEFT_BUTTON)) {
|
|
95
|
+ leftButton = new TitleBarLeftButtonParamsParser().parseSingleButton(params.getBundle(KEY_LEFT_BUTTON));
|
|
96
|
+
|
|
97
|
+ boolean backButtonHidden = params.getBoolean(KEY_BACK_BUTTON_HIDDEN, false);
|
|
98
|
+ if (backButtonHidden && leftButton.isBackButton()) {
|
|
99
|
+ leftButton = null;
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+ return leftButton;
|
56
|
103
|
}
|
57
|
104
|
|
58
|
105
|
public static List<ScreenParams> parseTabs(Bundle params) {
|