-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathExternalComponent.java
More file actions
57 lines (48 loc) · 1.63 KB
/
ExternalComponent.java
File metadata and controls
57 lines (48 loc) · 1.63 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
package com.reactnativenavigation.options;
import com.reactnativenavigation.options.params.NullText;
import com.reactnativenavigation.options.params.Text;
import com.reactnativenavigation.options.parsers.TextParser;
import org.json.JSONException;
import org.json.JSONObject;
public class ExternalComponent {
public Text name = new NullText();
public JSONObject passProps = new JSONObject();
public static ExternalComponent parse(JSONObject json) {
ExternalComponent options = new ExternalComponent();
if (json == null) {
return options;
}
options.name = TextParser.parse(json, "name");
if (!options.name.hasValue()) {
throw new RuntimeException("ExternalComponent must have a name");
}
options.passProps = parsePassProps(json);
return options;
}
private static JSONObject parsePassProps(JSONObject json) {
if (json.has("passProps")) {
try {
return json.getJSONObject("passProps");
} catch (JSONException e) {
e.printStackTrace();
}
}
return new JSONObject();
}
public void mergeWith(ExternalComponent other) {
if (other.name.hasValue()) {
name = other.name;
}
if (other.passProps.length() > 0) {
passProps = other.passProps;
}
}
public void mergeWithDefault(ExternalComponent defaultOptions) {
if (!name.hasValue()) {
name = defaultOptions.name;
}
if (passProps.length() == 0) {
passProps = defaultOptions.passProps;
}
}
}