Skip to content

Commit

Permalink
Implement startDelay + fix image scale transition (#6137)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guyca authored Apr 20, 2020
1 parent e80eb92 commit 334ab71
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.reactnativenavigation.utils

import android.animation.Animator
import android.animation.TimeInterpolator
import android.view.animation.Interpolator

fun Animator.withStartDelay(delay: Long): Animator {
startDelay = delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import androidx.core.animation.doOnStart
import com.facebook.react.views.text.ReactTextView
import com.facebook.react.views.view.ReactViewBackgroundDrawable
import com.reactnativenavigation.parse.SharedElementTransitionOptions
import com.reactnativenavigation.utils.ColorUtils
import com.reactnativenavigation.utils.ViewUtils
import com.reactnativenavigation.utils.withInterpolator
import com.reactnativenavigation.utils.withStartDelay
import com.reactnativenavigation.utils.*

class BackgroundColorAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(from, to) {
override fun shouldAnimateProperty(fromChild: ViewGroup, toChild: ViewGroup): Boolean {
Expand All @@ -35,7 +32,7 @@ class BackgroundColorAnimator(from: View, to: View) : PropertyAnimatorCreator<Vi
fromColor,
toColor
)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ClipBoundsAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactIm
startDrawingRect,
endDrawingRect
)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.reactnativenavigation.views.element.animators

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.animation.TypeEvaluator
import android.graphics.Rect
import android.view.View
import androidx.core.animation.addListener
import androidx.core.animation.doOnStart
import com.facebook.drawee.drawable.ScalingUtils.InterpolatingScaleType
import com.facebook.react.views.image.ReactImageView
import com.reactnativenavigation.parse.SharedElementTransitionOptions
Expand Down Expand Up @@ -38,7 +35,7 @@ class MatrixAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactImageV
}
null
}, 0, 1)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ScaleXAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(
to.scaleX = from.width.toFloat() / to.width
return ObjectAnimator
.ofFloat(to, View.SCALE_X, from.width.toFloat() / to.width, 1f)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.animation.Animator
import android.animation.ObjectAnimator
import android.view.View
import android.view.ViewGroup
import androidx.core.animation.addListener
import androidx.core.animation.doOnStart
import com.facebook.react.views.text.ReactTextView
import com.reactnativenavigation.parse.SharedElementTransitionOptions
import com.reactnativenavigation.utils.withDuration
Expand All @@ -23,7 +21,7 @@ class ScaleYAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(
to.scaleY = from.height.toFloat() / to.height
return ObjectAnimator
.ofFloat(to, View.SCALE_Y, from.height.toFloat() / to.height, 1f)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.animation.doOnStart
import com.facebook.react.views.text.ReactTextView
import com.reactnativenavigation.parse.SharedElementTransitionOptions
import com.reactnativenavigation.utils.ViewUtils
import com.reactnativenavigation.utils.withDuration
import com.reactnativenavigation.utils.withInterpolator
import com.reactnativenavigation.utils.withStartDelay

Expand All @@ -31,7 +32,7 @@ class XAnimator(from: View, to: View) : PropertyAnimatorCreator<View>(from, to)
to.translationX = dx.toFloat()
return ObjectAnimator
.ofFloat(to, TRANSLATION_X, dx.toFloat(), 0f)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.reactnativenavigation.views.element.animators

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.view.View
import android.view.View.TRANSLATION_Y
import android.view.ViewGroup
import androidx.core.animation.addListener
import androidx.core.animation.doOnStart
import com.facebook.react.views.text.ReactTextView
import com.reactnativenavigation.parse.SharedElementTransitionOptions
import com.reactnativenavigation.utils.ViewUtils
import com.reactnativenavigation.utils.withDuration

import com.reactnativenavigation.utils.withInterpolator
import com.reactnativenavigation.utils.withStartDelay

Expand All @@ -32,7 +31,7 @@ class YAnimator(from: View, to: View) : PropertyAnimatorCreator<View>(from, to)
to.translationY = dy.toFloat()
return ObjectAnimator
.ofFloat(to, TRANSLATION_Y, dy.toFloat(), 0f)
.setDuration(options.getDuration())
.withDuration(options.getDuration())
.withStartDelay(options.getStartDelay())
.withInterpolator(options.interpolation.interpolator)
}
Expand Down

0 comments on commit 334ab71

Please sign in to comment.