-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLayoutOptions.kt
More file actions
71 lines (57 loc) · 2.88 KB
/
LayoutOptions.kt
File metadata and controls
71 lines (57 loc) · 2.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
package com.reactnativenavigation.options.layout
import android.content.Context
import com.reactnativenavigation.options.LayoutDirection
import com.reactnativenavigation.options.OrientationOptions
import com.reactnativenavigation.options.params.*
import com.reactnativenavigation.options.params.Number
import com.reactnativenavigation.options.parsers.BoolParser
import com.reactnativenavigation.options.parsers.NumberParser
import org.json.JSONObject
class LayoutOptions {
@JvmField
var backgroundColor: ThemeColour = NullThemeColour()
@JvmField
var componentBackgroundColor: ThemeColour = NullThemeColour()
@JvmField
var topMargin: Number = NullNumber()
@JvmField
var adjustResize: Bool = NullBool()
@JvmField
var orientation = OrientationOptions()
@JvmField
var direction = LayoutDirection.DEFAULT
var insets: LayoutInsets = LayoutInsets()
fun mergeWith(other: LayoutOptions) {
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor
if (other.componentBackgroundColor.hasValue()) componentBackgroundColor = other.componentBackgroundColor
if (other.topMargin.hasValue()) topMargin = other.topMargin
if (other.orientation.hasValue()) orientation = other.orientation
if (other.direction.hasValue()) direction = other.direction
if (other.adjustResize.hasValue()) adjustResize = other.adjustResize
insets.merge(other.insets, null)
}
fun mergeWithDefault(defaultOptions: LayoutOptions) {
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor
if (!componentBackgroundColor.hasValue()) componentBackgroundColor = defaultOptions.componentBackgroundColor
if (!topMargin.hasValue()) topMargin = defaultOptions.topMargin
if (!orientation.hasValue()) orientation = defaultOptions.orientation
if (!direction.hasValue()) direction = defaultOptions.direction
if (!adjustResize.hasValue()) adjustResize = defaultOptions.adjustResize
insets.merge(null, defaultOptions.insets)
}
companion object {
@JvmStatic
fun parse(context: Context?, json: JSONObject?): LayoutOptions {
val result = LayoutOptions()
if (json == null) return result
result.backgroundColor = ThemeColour.parse(context!!, json.optJSONObject("backgroundColor"))
result.componentBackgroundColor = ThemeColour.parse(context, json.optJSONObject("componentBackgroundColor"))
result.topMargin = NumberParser.parse(json, "topMargin")
result.insets = LayoutInsets.parse(json.optJSONObject("insets"))
result.orientation = OrientationOptions.parse(json)
result.direction = LayoutDirection.fromString(json.optString("direction", ""))
result.adjustResize = BoolParser.parse(json, "adjustResize")
return result
}
}
}