-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathFabOptions.java
More file actions
133 lines (114 loc) · 4.88 KB
/
FabOptions.java
File metadata and controls
133 lines (114 loc) · 4.88 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
133
package com.reactnativenavigation.options;
import android.content.Context;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.options.params.NullBool;
import com.reactnativenavigation.options.params.NullText;
import com.reactnativenavigation.options.params.ThemeColour;
import com.reactnativenavigation.options.params.NullThemeColour;
import com.reactnativenavigation.options.params.Text;
import com.reactnativenavigation.options.parsers.BoolParser;
import com.reactnativenavigation.options.parsers.TextParser;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
public class FabOptions {
public static FabOptions parse(Context context, JSONObject json) {
FabOptions options = new FabOptions();
if (json == null) return options;
options.id = TextParser.parse(json, "id");
options.backgroundColor = ThemeColour.parse(context, json.optJSONObject("backgroundColor"));
options.clickColor = ThemeColour.parse(context, json.optJSONObject("clickColor"));
options.rippleColor = ThemeColour.parse(context, json.optJSONObject("rippleColor"));
options.visible = BoolParser.parse(json, "visible");
if (json.has("icon")) {
options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
}
options.iconColor = ThemeColour.parse(context, json.optJSONObject("iconColor"));
if (json.has("actions")) {
JSONArray fabsArray = json.optJSONArray("actions");
for (int i = 0; i < fabsArray.length(); i++) {
options.actionsArray.add(FabOptions.parse(context, fabsArray.optJSONObject(i)));
}
}
options.alignHorizontally = TextParser.parse(json, "alignHorizontally");
options.alignVertically = TextParser.parse(json, "alignVertically");
options.hideOnScroll = BoolParser.parse(json, "hideOnScroll");
options.size = TextParser.parse(json, "size");
return options;
}
public Text id = new NullText();
public ThemeColour backgroundColor = new NullThemeColour();
public ThemeColour clickColor = new NullThemeColour();
public ThemeColour rippleColor = new NullThemeColour();
public Text icon = new NullText();
public ThemeColour iconColor = new NullThemeColour();
public Bool visible = new NullBool();
public ArrayList<FabOptions> actionsArray = new ArrayList<>();
public Text alignHorizontally = new NullText();
public Text alignVertically = new NullText();
public Bool hideOnScroll = new NullBool();
public Text size = new NullText();
void mergeWith(final FabOptions other) {
if (other.id.hasValue()) {
id = other.id;
}
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
if (other.clickColor.hasValue()) clickColor = other.clickColor;
if (other.iconColor.hasValue()) iconColor = other.iconColor;
if (other.rippleColor.hasValue()) rippleColor = other.rippleColor;
if (other.visible.hasValue()) {
visible = other.visible;
}
if (other.icon.hasValue()) {
icon = other.icon;
}
if (other.actionsArray.size() > 0) {
actionsArray = other.actionsArray;
}
if (other.alignVertically.hasValue()) {
alignVertically = other.alignVertically;
}
if (other.alignHorizontally.hasValue()) {
alignHorizontally = other.alignHorizontally;
}
if (other.hideOnScroll.hasValue()) {
hideOnScroll = other.hideOnScroll;
}
if (other.size.hasValue()) {
size = other.size;
}
}
void mergeWithDefault(FabOptions defaultOptions) {
if (!id.hasValue()) {
id = defaultOptions.id;
}
if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
if (!rippleColor.hasValue()) rippleColor = defaultOptions.rippleColor;
if (!clickColor.hasValue()) clickColor = defaultOptions.clickColor;
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
if (!visible.hasValue()) {
visible = defaultOptions.visible;
}
if (!icon.hasValue()) {
icon = defaultOptions.icon;
}
if (actionsArray.size() == 0) {
actionsArray = defaultOptions.actionsArray;
}
if (!alignHorizontally.hasValue()) {
alignHorizontally = defaultOptions.alignHorizontally;
}
if (!alignVertically.hasValue()) {
alignVertically = defaultOptions.alignVertically;
}
if (!hideOnScroll.hasValue()) {
hideOnScroll = defaultOptions.hideOnScroll;
}
if (!size.hasValue()) {
size = defaultOptions.size;
}
}
public boolean hasValue() {
return id.hasValue() || icon.hasValue();
}
}