-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBottomTabsOptions.java
More file actions
132 lines (121 loc) · 7.7 KB
/
BottomTabsOptions.java
File metadata and controls
132 lines (121 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.reactnativenavigation.options;
import android.content.Context;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.options.params.BottomTabsLayoutStyle;
import com.reactnativenavigation.options.params.Fraction;
import com.reactnativenavigation.options.params.NullBool;
import com.reactnativenavigation.options.params.NullFraction;
import com.reactnativenavigation.options.params.NullNumber;
import com.reactnativenavigation.options.params.NullText;
import com.reactnativenavigation.options.params.Number;
import com.reactnativenavigation.options.params.ThemeColour;
import com.reactnativenavigation.options.params.NullThemeColour;
import com.reactnativenavigation.options.params.Text;
import com.reactnativenavigation.options.params.TitleDisplayMode;
import com.reactnativenavigation.options.parsers.BoolParser;
import com.reactnativenavigation.options.parsers.FractionParser;
import com.reactnativenavigation.options.parsers.NumberParser;
import com.reactnativenavigation.options.parsers.TextParser;
import org.json.JSONObject;
public class BottomTabsOptions {
public static BottomTabsOptions parse(Context context, JSONObject json) {
BottomTabsOptions options = new BottomTabsOptions();
if (json == null) return options;
options.backgroundColor = ThemeColour.parse(context, json.optJSONObject("backgroundColor"));
options.layoutStyle = BottomTabsLayoutStyle.fromString(json.optString("layoutStyle"));
options.bottomMargin = FractionParser.parse(json, "bottomMargin");
options.cornerRadius = FractionParser.parse(json, "cornerRadius");
options.translucent = BoolParser.parse(json, "translucent");
options.blurRadius = FractionParser.parse(json, "blurRadius");
options.currentTabId = TextParser.parse(json, "currentTabId");
options.currentTabIndex = NumberParser.parse(json, "currentTabIndex");
options.hideOnScroll = BoolParser.parse(json, "hideOnScroll");
options.visible = BoolParser.parse(json, "visible");
options.drawBehind = BoolParser.parse(json, "drawBehind");
options.preferLargeIcons = BoolParser.parse(json, "preferLargeIcons");
options.animate = BoolParser.parse(json, "animate");
options.animateTabSelection = BoolParser.parse(json, "animateTabSelection");
options.elevation = FractionParser.parse(json, "elevation");
options.testId = TextParser.parse(json, "testID");
options.titleDisplayMode = TitleDisplayMode.fromString(json.optString("titleDisplayMode"));
options.tabsAttachMode = TabsAttachMode.fromString(json.optString("tabsAttachMode"));
options.borderColor = ThemeColour.parse(context, json.optJSONObject("borderColor"));
options.borderWidth = FractionParser.parse(json, "borderWidth");
options.shadowOptions = ShadowOptionsKt.parseShadowOptions(context, json.optJSONObject("shadow"));
return options;
}
public ThemeColour backgroundColor = new NullThemeColour();
public BottomTabsLayoutStyle layoutStyle = BottomTabsLayoutStyle.LAYOUT_STYLE_UNDEFINED;
public Fraction bottomMargin = new NullFraction();
public Fraction cornerRadius = new NullFraction();
public Bool translucent = new NullBool();
public Fraction blurRadius = new NullFraction();
public Bool hideOnScroll = new NullBool();
public Bool visible = new NullBool();
public Bool drawBehind = new NullBool();
public Bool animate = new NullBool();
public Bool animateTabSelection = new NullBool();
public Bool preferLargeIcons = new NullBool();
public Number currentTabIndex = new NullNumber();
public Fraction elevation = new NullFraction();
public Text currentTabId = new NullText();
public Text testId = new NullText();
public TitleDisplayMode titleDisplayMode = TitleDisplayMode.UNDEFINED;
public TabsAttachMode tabsAttachMode = TabsAttachMode.UNDEFINED;
public ThemeColour borderColor = new NullThemeColour();
public Fraction borderWidth = new NullFraction();
public ShadowOptions shadowOptions = NullShadowOptions.INSTANCE;
void mergeWith(final BottomTabsOptions other) {
if (other.currentTabId.hasValue()) currentTabId = other.currentTabId;
if (other.currentTabIndex.hasValue()) currentTabIndex = other.currentTabIndex;
if (other.hideOnScroll.hasValue()) hideOnScroll = other.hideOnScroll;
if (other.visible.hasValue()) visible = other.visible;
if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
if (other.animate.hasValue()) animate = other.animate;
if (other.animateTabSelection.hasValue()) animateTabSelection = other.animateTabSelection;
if (other.preferLargeIcons.hasValue()) preferLargeIcons = other.preferLargeIcons;
if (other.elevation.hasValue()) elevation = other.elevation;
if (other.testId.hasValue()) testId = other.testId;
if (other.titleDisplayMode.hasValue()) titleDisplayMode = other.titleDisplayMode;
if (other.tabsAttachMode.hasValue()) tabsAttachMode = other.tabsAttachMode;
if (other.borderWidth.hasValue()) borderWidth = other.borderWidth;
if (other.shadowOptions.hasValue()) shadowOptions = shadowOptions.copy().mergeWith(other.shadowOptions);
if (other.borderColor.hasValue()) borderColor = other.borderColor;
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
if (other.translucent.hasValue()) translucent = other.translucent;
if (other.blurRadius.hasValue()) blurRadius = other.blurRadius;
if (other.layoutStyle.hasValue()) layoutStyle = other.layoutStyle;
if (other.bottomMargin.hasValue()) bottomMargin = other.bottomMargin;
if (other.cornerRadius.hasValue()) cornerRadius = other.cornerRadius;
}
void mergeWithDefault(final BottomTabsOptions defaultOptions) {
if (!borderColor.hasValue()) borderColor = defaultOptions.borderColor;
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
if (!translucent.hasValue()) translucent = defaultOptions.translucent;
if (!blurRadius.hasValue()) blurRadius = defaultOptions.blurRadius;
if (!layoutStyle.hasValue()) layoutStyle = defaultOptions.layoutStyle;
if (!bottomMargin.hasValue()) bottomMargin = defaultOptions.bottomMargin;
if (!cornerRadius.hasValue()) cornerRadius = defaultOptions.cornerRadius;
if (!currentTabId.hasValue()) currentTabId = defaultOptions.currentTabId;
if (!currentTabIndex.hasValue()) currentTabIndex = defaultOptions.currentTabIndex;
if (!hideOnScroll.hasValue()) hideOnScroll = defaultOptions.hideOnScroll;
if (!visible.hasValue()) visible = defaultOptions.visible;
if (!drawBehind.hasValue()) drawBehind = defaultOptions.drawBehind;
if (!animate.hasValue()) animate = defaultOptions.animate;
if (!animateTabSelection.hasValue()) animateTabSelection = defaultOptions.animateTabSelection;
if (!preferLargeIcons.hasValue()) preferLargeIcons = defaultOptions.preferLargeIcons;
if (!elevation.hasValue()) elevation = defaultOptions.elevation;
if (!titleDisplayMode.hasValue()) titleDisplayMode = defaultOptions.titleDisplayMode;
if (!tabsAttachMode.hasValue()) tabsAttachMode = defaultOptions.tabsAttachMode;
if (!borderWidth.hasValue()) borderWidth = defaultOptions.borderWidth;
if (!shadowOptions.hasValue())
shadowOptions = shadowOptions.copy().mergeWithDefaults(defaultOptions.shadowOptions);
}
public boolean isHiddenOrDrawBehind() {
return visible.isFalse() || drawBehind.isTrue();
}
public void clearOneTimeOptions() {
currentTabId = new NullText();
currentTabIndex = new NullNumber();
}
}