-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathShadowOptions.kt
More file actions
49 lines (40 loc) · 1.78 KB
/
ShadowOptions.kt
File metadata and controls
49 lines (40 loc) · 1.78 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
package com.reactnativenavigation.options
import android.content.Context
import com.reactnativenavigation.options.params.Fraction
import com.reactnativenavigation.options.params.NullFraction
import com.reactnativenavigation.options.params.NullThemeColour
import com.reactnativenavigation.options.params.ThemeColour
import com.reactnativenavigation.options.parsers.FractionParser
import org.json.JSONObject
fun parseShadowOptions(context: Context, shadowJson: JSONObject?): ShadowOptions = shadowJson?.let { json ->
ShadowOptions(
ThemeColour.parse(context, json.optJSONObject("color")), FractionParser.parse(json, "radius"),
FractionParser
.parse(
json,
"opacity"
)
)
} ?: NullShadowOptions
object NullShadowOptions : ShadowOptions() {
override fun hasValue(): Boolean = false
}
open class ShadowOptions(
var color: ThemeColour = NullThemeColour(), var radius: Fraction = NullFraction(), var opacity: Fraction =
NullFraction()
) {
fun copy(): ShadowOptions = ShadowOptions(this.color, this.radius, this.opacity)
fun mergeWith(other: ShadowOptions): ShadowOptions {
if(other.color.hasValue()) this.color = other.color;
if (other.opacity.hasValue()) this.opacity = other.opacity
if (other.radius.hasValue()) this.radius = other.radius
return this
}
fun mergeWithDefaults(defaultOptions: ShadowOptions = NullShadowOptions): ShadowOptions {
if(!this.color.hasValue()) this.color = defaultOptions.color;
if (!this.opacity.hasValue()) this.opacity = defaultOptions.opacity
if (!this.radius.hasValue()) this.radius = defaultOptions.radius
return this
}
open fun hasValue() = color.hasValue() || radius.hasValue() || opacity.hasValue()
}