-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathTransitionAnimationOptions.kt
More file actions
58 lines (50 loc) · 2.43 KB
/
TransitionAnimationOptions.kt
File metadata and controls
58 lines (50 loc) · 2.43 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 androidx.annotation.RestrictTo
import com.reactnativenavigation.options.params.Bool
import org.json.JSONObject
fun parseTransitionAnimationOptions(jsonObject: JSONObject?): TransitionAnimationOptions {
return jsonObject?.let {
val modalAnimationOptions = TransitionAnimationOptions(
AnimationOptions(jsonObject.optJSONObject("enter")),
AnimationOptions(jsonObject.optJSONObject("exit"))
)
if (jsonObject.has("sharedElementTransitions")) {
modalAnimationOptions.sharedElements = SharedElements.parse(jsonObject)
}
if (jsonObject.has("elementTransitions")) {
modalAnimationOptions.elementTransitions = ElementTransitions.parse(jsonObject)
}
modalAnimationOptions
} ?: TransitionAnimationOptions()
}
open class TransitionAnimationOptions(
val enter: AnimationOptions = AnimationOptions(),
val exit: AnimationOptions = AnimationOptions(),
override var sharedElements: SharedElements = SharedElements(),
override var elementTransitions: ElementTransitions = ElementTransitions()
) : LayoutAnimation {
open fun hasValue() = enter.hasValue() || exit.hasValue() || sharedElements.hasValue() || elementTransitions.hasValue()
open fun mergeWith(other: TransitionAnimationOptions) {
this.enter.mergeWith(other.enter)
this.exit.mergeWith(other.exit)
this.sharedElements.mergeWith(other.sharedElements)
this.elementTransitions.mergeWith(other.elementTransitions)
}
open fun mergeWithDefault(other: TransitionAnimationOptions) {
if (!this.enter.hasValue()) this.enter.mergeWithDefault(other.enter)
if (!this.exit.hasValue()) this.exit.mergeWithDefault(other.exit)
if (!this.sharedElements.hasValue()) this.sharedElements.mergeWithDefault(other.sharedElements)
if (!this.elementTransitions.hasValue()) this.elementTransitions.mergeWithDefault(other.elementTransitions)
}
open fun hasElementTransitions() = sharedElements.hasValue() || elementTransitions.hasValue()
@RestrictTo(RestrictTo.Scope.TESTS)
fun setWaitForRender(waitForRender: Bool) {
this.enter.waitForRender = waitForRender
this.exit.waitForRender = waitForRender
}
@RestrictTo(RestrictTo.Scope.TESTS)
fun toggle(enabled: Bool) {
this.enter.enabled = enabled
this.exit.enabled = enabled
}
}