-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLayoutInsets.kt
More file actions
44 lines (38 loc) · 1.2 KB
/
LayoutInsets.kt
File metadata and controls
44 lines (38 loc) · 1.2 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
package com.reactnativenavigation.options.layout
import com.reactnativenavigation.utils.dp
import org.json.JSONObject
class LayoutInsets(
var top: Int?=null,
var left: Int?=null,
var bottom: Int?=null,
var right: Int?=null
) {
fun merge(toMerge: LayoutInsets?, defaults: LayoutInsets?) {
toMerge?.let { options->
options.top?.let { this.top = it }
options.bottom?.let { this.bottom = it }
options.left?.let { this.left = it }
options.right?.let { this.right = it }
}
defaults?.let {
options->
top = top?:options.top
left = left?:options.left
right = right?:options.right
bottom = bottom?:options.bottom
}
}
companion object{
fun parse(jsonObject: JSONObject?): LayoutInsets {
return LayoutInsets(
jsonObject?.optInt("top")?.dp,
jsonObject?.optInt("left")?.dp,
jsonObject?.optInt("bottom")?.dp,
jsonObject?.optInt("right")?.dp
)
}
}
fun hasValue(): Boolean {
return top!=null || bottom!=null || left!=null || right!=null
}
}