Browse Source

Implement startDelay + fix image scale transition (#6137)

This commit adds support to the startDelay option in shared element transitions on Android. It also fixes image scale transition which only animated the image's scale type, but not its bounds.
Guy Carmeli 4 years ago
parent
commit
334ab7174a
No account linked to committer's email address

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/Animator.kt View File

@@ -2,7 +2,6 @@ package com.reactnativenavigation.utils
2 2
 
3 3
 import android.animation.Animator
4 4
 import android.animation.TimeInterpolator
5
-import android.view.animation.Interpolator
6 5
 
7 6
 fun Animator.withStartDelay(delay: Long): Animator {
8 7
     startDelay = delay

+ 2
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/BackgroundColorAnimator.kt View File

@@ -10,10 +10,7 @@ import androidx.core.animation.doOnStart
10 10
 import com.facebook.react.views.text.ReactTextView
11 11
 import com.facebook.react.views.view.ReactViewBackgroundDrawable
12 12
 import com.reactnativenavigation.parse.SharedElementTransitionOptions
13
-import com.reactnativenavigation.utils.ColorUtils
14
-import com.reactnativenavigation.utils.ViewUtils
15
-import com.reactnativenavigation.utils.withInterpolator
16
-import com.reactnativenavigation.utils.withStartDelay
13
+import com.reactnativenavigation.utils.*
17 14
 
18 15
 class BackgroundColorAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(from, to) {
19 16
     override fun shouldAnimateProperty(fromChild: ViewGroup, toChild: ViewGroup): Boolean {
@@ -35,7 +32,7 @@ class BackgroundColorAnimator(from: View, to: View) : PropertyAnimatorCreator<Vi
35 32
                         fromColor,
36 33
                         toColor
37 34
                 )
38
-                .setDuration(options.getDuration())
35
+                .withDuration(options.getDuration())
39 36
                 .withStartDelay(options.getStartDelay())
40 37
                 .withInterpolator(options.interpolation.interpolator)
41 38
     }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/ClipBoundsAnimator.kt View File

@@ -24,7 +24,7 @@ class ClipBoundsAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactIm
24 24
                 startDrawingRect,
25 25
                 endDrawingRect
26 26
         )
27
-                .setDuration(options.getDuration())
27
+                .withDuration(options.getDuration())
28 28
                 .withStartDelay(options.getStartDelay())
29 29
                 .withInterpolator(options.interpolation.interpolator)
30 30
     }

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/MatrixAnimator.kt View File

@@ -1,13 +1,10 @@
1 1
 package com.reactnativenavigation.views.element.animators
2 2
 
3 3
 import android.animation.Animator
4
-import android.animation.AnimatorListenerAdapter
5 4
 import android.animation.ObjectAnimator
6 5
 import android.animation.TypeEvaluator
7 6
 import android.graphics.Rect
8 7
 import android.view.View
9
-import androidx.core.animation.addListener
10
-import androidx.core.animation.doOnStart
11 8
 import com.facebook.drawee.drawable.ScalingUtils.InterpolatingScaleType
12 9
 import com.facebook.react.views.image.ReactImageView
13 10
 import com.reactnativenavigation.parse.SharedElementTransitionOptions
@@ -38,7 +35,7 @@ class MatrixAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactImageV
38 35
                         }
39 36
                         null
40 37
                     }, 0, 1)
41
-                    .setDuration(options.getDuration())
38
+                    .withDuration(options.getDuration())
42 39
                     .withStartDelay(options.getStartDelay())
43 40
                     .withInterpolator(options.interpolation.interpolator)
44 41
         }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/ScaleXAnimator.kt View File

@@ -23,7 +23,7 @@ class ScaleXAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(
23 23
         to.scaleX = from.width.toFloat() / to.width
24 24
         return ObjectAnimator
25 25
                 .ofFloat(to, View.SCALE_X, from.width.toFloat() / to.width, 1f)
26
-                .setDuration(options.getDuration())
26
+                .withDuration(options.getDuration())
27 27
                 .withStartDelay(options.getStartDelay())
28 28
                 .withInterpolator(options.interpolation.interpolator)
29 29
     }

+ 1
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/ScaleYAnimator.kt View File

@@ -4,8 +4,6 @@ import android.animation.Animator
4 4
 import android.animation.ObjectAnimator
5 5
 import android.view.View
6 6
 import android.view.ViewGroup
7
-import androidx.core.animation.addListener
8
-import androidx.core.animation.doOnStart
9 7
 import com.facebook.react.views.text.ReactTextView
10 8
 import com.reactnativenavigation.parse.SharedElementTransitionOptions
11 9
 import com.reactnativenavigation.utils.withDuration
@@ -23,7 +21,7 @@ class ScaleYAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(
23 21
         to.scaleY = from.height.toFloat() / to.height
24 22
         return ObjectAnimator
25 23
                 .ofFloat(to, View.SCALE_Y, from.height.toFloat() / to.height, 1f)
26
-                .setDuration(options.getDuration())
24
+                .withDuration(options.getDuration())
27 25
                 .withStartDelay(options.getStartDelay())
28 26
                 .withInterpolator(options.interpolation.interpolator)
29 27
     }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/XAnimator.kt View File

@@ -10,6 +10,7 @@ import androidx.core.animation.doOnStart
10 10
 import com.facebook.react.views.text.ReactTextView
11 11
 import com.reactnativenavigation.parse.SharedElementTransitionOptions
12 12
 import com.reactnativenavigation.utils.ViewUtils
13
+import com.reactnativenavigation.utils.withDuration
13 14
 import com.reactnativenavigation.utils.withInterpolator
14 15
 import com.reactnativenavigation.utils.withStartDelay
15 16
 
@@ -31,7 +32,7 @@ class XAnimator(from: View, to: View) : PropertyAnimatorCreator<View>(from, to)
31 32
         to.translationX = dx.toFloat()
32 33
         return ObjectAnimator
33 34
                 .ofFloat(to, TRANSLATION_X, dx.toFloat(), 0f)
34
-                .setDuration(options.getDuration())
35
+                .withDuration(options.getDuration())
35 36
                 .withStartDelay(options.getStartDelay())
36 37
                 .withInterpolator(options.interpolation.interpolator)
37 38
     }

+ 3
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/element/animators/YAnimator.kt View File

@@ -1,16 +1,15 @@
1 1
 package com.reactnativenavigation.views.element.animators
2 2
 
3 3
 import android.animation.Animator
4
-import android.animation.AnimatorListenerAdapter
5 4
 import android.animation.ObjectAnimator
6 5
 import android.view.View
7 6
 import android.view.View.TRANSLATION_Y
8 7
 import android.view.ViewGroup
9
-import androidx.core.animation.addListener
10
-import androidx.core.animation.doOnStart
11 8
 import com.facebook.react.views.text.ReactTextView
12 9
 import com.reactnativenavigation.parse.SharedElementTransitionOptions
13 10
 import com.reactnativenavigation.utils.ViewUtils
11
+import com.reactnativenavigation.utils.withDuration
12
+
14 13
 import com.reactnativenavigation.utils.withInterpolator
15 14
 import com.reactnativenavigation.utils.withStartDelay
16 15
 
@@ -32,7 +31,7 @@ class YAnimator(from: View, to: View) : PropertyAnimatorCreator<View>(from, to)
32 31
         to.translationY = dy.toFloat()
33 32
         return ObjectAnimator
34 33
                 .ofFloat(to, TRANSLATION_Y, dy.toFloat(), 0f)
35
-                .setDuration(options.getDuration())
34
+                .withDuration(options.getDuration())
36 35
                 .withStartDelay(options.getStartDelay())
37 36
                 .withInterpolator(options.interpolation.interpolator)
38 37
     }