1
1
package com.airbnb.android.react.lottie
2
2
3
- import com.airbnb.lottie.LottieAnimationView
4
- import java.lang.ref.WeakReference
3
+ import android.graphics.ColorFilter
5
4
import android.widget.ImageView
6
- import com.facebook.react.bridge.ReadableArray
7
- import com.airbnb.lottie.RenderMode
8
- import com.airbnb.lottie.TextDelegate
5
+ import com.airbnb.lottie.LottieAnimationView
9
6
import com.airbnb.lottie.LottieDrawable
10
- import com.facebook.react.bridge.ReadableType
11
- import com.facebook.react.bridge.ColorPropConverter
12
- import android.graphics.ColorFilter
7
+ import com.airbnb.lottie.LottieProperty
8
+ import com.airbnb.lottie.RenderMode
13
9
import com.airbnb.lottie.SimpleColorFilter
10
+ import com.airbnb.lottie.TextDelegate
14
11
import com.airbnb.lottie.model.KeyPath
15
12
import com.airbnb.lottie.value.LottieValueCallback
16
- import com.airbnb.lottie.LottieProperty
13
+ import com.facebook.react.bridge.ColorPropConverter
14
+ import com.facebook.react.bridge.ReadableArray
15
+ import com.facebook.react.bridge.ReadableType
16
+ import java.lang.ref.WeakReference
17
17
import java.util.regex.Pattern
18
18
19
19
/* *
20
- * Class responsible for applying the properties to the LottieView.
21
- * The way react-native works makes it impossible to predict in which order properties will be set,
22
- * also some of the properties of the LottieView needs to be set simultaneously.
20
+ * Class responsible for applying the properties to the LottieView. The way react-native works makes
21
+ * it impossible to predict in which order properties will be set, also some of the properties of
22
+ * the LottieView needs to be set simultaneously.
23
23
*
24
- * To solve this, instance of this class accumulates all changes to the view and applies them at
25
- * the end of react transaction, so it could control how changes are applied.
24
+ * To solve this, instance of this class accumulates all changes to the view and applies them at the
25
+ * end of react transaction, so it could control how changes are applied.
26
26
*/
27
27
class LottieAnimationViewPropertyManager (view : LottieAnimationView ) {
28
28
private val viewWeakReference: WeakReference <LottieAnimationView >
@@ -48,26 +48,26 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
48
48
var animationJson: String? = null
49
49
var progress: Float? = null
50
50
var loop: Boolean? = null
51
+ var autoPlay: Boolean? = null
51
52
var speed: Float? = null
52
53
53
54
init {
54
55
viewWeakReference = WeakReference (view)
55
56
}
56
57
57
58
/* *
58
- * Updates the view with changed fields.
59
- * Majority of the properties here are independent so they are has to be reset to null
60
- * as soon as view is updated with the value.
59
+ * Updates the view with changed fields. Majority of the properties here are independent so they
60
+ * are has to be reset to null as soon as view is updated with the value.
61
61
*
62
- * The only exception from this rule is the group of the properties for the animation.
63
- * For now this is animationName and cacheStrategy. These two properties are should be set
62
+ * The only exception from this rule is the group of the properties for the animation. For now
63
+ * this is animationName and cacheStrategy. These two properties are should be set
64
64
* simultaneously if the dirty flag is set.
65
65
*/
66
66
fun commitChanges () {
67
67
val view = viewWeakReference.get() ? : return
68
68
69
69
textFilters?.let {
70
- if (it.size() > 0 ) {
70
+ if (it.size() > 0 ) {
71
71
val textDelegate = TextDelegate (view)
72
72
for (i in 0 until textFilters!! .size()) {
73
73
val current = textFilters!! .getMap(i)
@@ -99,6 +99,13 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
99
99
loop = null
100
100
}
101
101
102
+ autoPlay?.let {
103
+ if (it && ! view.isAnimating) {
104
+ view.playAnimation()
105
+ }
106
+ autoPlay = null
107
+ }
108
+
102
109
speed?.let {
103
110
view.speed = it
104
111
speed = null
@@ -114,9 +121,7 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
114
121
renderMode = null
115
122
}
116
123
117
- layerType?.let {
118
- view.setLayerType(it, null )
119
- }
124
+ layerType?.let { view.setLayerType(it, null ) }
120
125
121
126
imageAssetsFolder?.let {
122
127
view.imageAssetsFolder = it
@@ -133,11 +138,12 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
133
138
for (i in 0 until it.size()) {
134
139
val current = it.getMap(i)
135
140
136
- val color: Int = if (current.getType(" color" ) == ReadableType .Map ) {
137
- ColorPropConverter .getColor(current.getMap(" color" ), view.context)
138
- } else {
139
- current.getInt(" color" )
140
- }
141
+ val color: Int =
142
+ if (current.getType(" color" ) == ReadableType .Map ) {
143
+ ColorPropConverter .getColor(current.getMap(" color" ), view.context)
144
+ } else {
145
+ current.getInt(" color" )
146
+ }
141
147
142
148
val path = current.getString(" keypath" )
143
149
val pathWithGlobStar = " $path .**"
@@ -153,4 +159,4 @@ class LottieAnimationViewPropertyManager(view: LottieAnimationView) {
153
159
}
154
160
}
155
161
}
156
- }
162
+ }
0 commit comments