@@ -33,6 +33,7 @@ class EaseView(context: Context) : ReactViewGroup(context) {
3333 var transitionDamping: Float = 15.0f
3434 var transitionStiffness: Float = 120.0f
3535 var transitionMass: Float = 1.0f
36+ var transitionLoop: String = " none"
3637
3738 // --- Hardware layer ---
3839 var useHardwareLayer: Boolean = true
@@ -116,33 +117,33 @@ class EaseView(context: Context) : ReactViewGroup(context) {
116117 this .rotation = initialAnimateRotate
117118
118119 if (initialAnimateOpacity != opacity) {
119- animateProperty(" alpha" , DynamicAnimation .ALPHA , initialAnimateOpacity, opacity)
120+ animateProperty(" alpha" , DynamicAnimation .ALPHA , initialAnimateOpacity, opacity, loop = true )
120121 } else {
121122 this .alpha = opacity
122123 }
123124
124125 if (initialAnimateTranslateX != translateX) {
125- animateProperty(" translationX" , DynamicAnimation .TRANSLATION_X , initialAnimateTranslateX, translateX)
126+ animateProperty(" translationX" , DynamicAnimation .TRANSLATION_X , initialAnimateTranslateX, translateX, loop = true )
126127 } else {
127128 this .translationX = translateX
128129 }
129130
130131 if (initialAnimateTranslateY != translateY) {
131- animateProperty(" translationY" , DynamicAnimation .TRANSLATION_Y , initialAnimateTranslateY, translateY)
132+ animateProperty(" translationY" , DynamicAnimation .TRANSLATION_Y , initialAnimateTranslateY, translateY, loop = true )
132133 } else {
133134 this .translationY = translateY
134135 }
135136
136137 if (initialAnimateScale != scale) {
137- animateProperty(" scaleX" , DynamicAnimation .SCALE_X , initialAnimateScale, scale)
138- animateProperty(" scaleY" , DynamicAnimation .SCALE_Y , initialAnimateScale, scale)
138+ animateProperty(" scaleX" , DynamicAnimation .SCALE_X , initialAnimateScale, scale, loop = true )
139+ animateProperty(" scaleY" , DynamicAnimation .SCALE_Y , initialAnimateScale, scale, loop = true )
139140 } else {
140141 this .scaleX = scale
141142 this .scaleY = scale
142143 }
143144
144145 if (initialAnimateRotate != rotate) {
145- animateProperty(" rotation" , DynamicAnimation .ROTATION , initialAnimateRotate, rotate)
146+ animateProperty(" rotation" , DynamicAnimation .ROTATION , initialAnimateRotate, rotate, loop = true )
146147 } else {
147148 this .rotation = rotate
148149 }
@@ -204,22 +205,31 @@ class EaseView(context: Context) : ReactViewGroup(context) {
204205 propertyName : String ,
205206 viewProperty : DynamicAnimation .ViewProperty ,
206207 fromValue : Float ,
207- toValue : Float
208+ toValue : Float ,
209+ loop : Boolean = false
208210 ) {
209211 if (transitionType == " spring" ) {
210212 animateSpring(viewProperty, toValue)
211213 } else {
212- animateTiming(propertyName, fromValue, toValue)
214+ animateTiming(propertyName, fromValue, toValue, loop )
213215 }
214216 }
215217
216- private fun animateTiming (propertyName : String , fromValue : Float , toValue : Float ) {
218+ private fun animateTiming (propertyName : String , fromValue : Float , toValue : Float , loop : Boolean = false ) {
217219 cancelSpringForProperty(propertyName)
218220 runningAnimators[propertyName]?.cancel()
219221
220222 val animator = ObjectAnimator .ofFloat(this , propertyName, fromValue, toValue).apply {
221223 duration = transitionDuration.toLong()
222224 interpolator = getInterpolator(transitionEasing)
225+ if (loop && transitionLoop != " none" ) {
226+ repeatCount = ObjectAnimator .INFINITE
227+ repeatMode = if (transitionLoop == " reverse" ) {
228+ ObjectAnimator .REVERSE
229+ } else {
230+ ObjectAnimator .RESTART
231+ }
232+ }
223233 addListener(object : AnimatorListenerAdapter () {
224234 override fun onAnimationStart (animation : Animator ) {
225235 this @EaseView.onEaseAnimationStart()
@@ -324,5 +334,6 @@ class EaseView(context: Context) : ReactViewGroup(context) {
324334 prevRotate = null
325335
326336 isFirstMount = true
337+ transitionLoop = " none"
327338 }
328339}
0 commit comments