react-native-navigation的迁移库

XAnimator.kt 1003B

12345678910111213141516171819202122232425262728
  1. package com.reactnativenavigation.views.element.animators
  2. import android.animation.Animator
  3. import android.animation.ObjectAnimator
  4. import android.view.View
  5. import android.view.View.TRANSLATION_X
  6. import com.facebook.react.views.text.ReactTextView
  7. import com.reactnativenavigation.parse.SharedElementTransitionOptions
  8. import com.reactnativenavigation.utils.ViewUtils
  9. class XAnimator(from: View, to: View) : PropertyAnimatorCreator<View>(from, to) {
  10. private val dx: Int
  11. init {
  12. val fromXy = ViewUtils.getLocationOnScreen(from)
  13. val toXy = ViewUtils.getLocationOnScreen(to)
  14. dx = fromXy.x - toXy.x
  15. to.pivotX = 0f
  16. }
  17. override fun excludedViews() = listOf(ReactTextView::class.java)
  18. override fun shouldAnimateProperty(fromChild: View, toChild: View) = dx != 0
  19. override fun create(options: SharedElementTransitionOptions): Animator {
  20. return ObjectAnimator.ofFloat(to, TRANSLATION_X, dx.toFloat(), 0f).setDuration(options.getDuration())
  21. }
  22. }