react-native-navigation的迁移库

TextChangeAnimator.kt 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.reactnativenavigation.views.element.animators
  2. import android.animation.Animator
  3. import android.graphics.Rect
  4. import android.view.View
  5. import android.view.ViewGroup
  6. import android.widget.TextView
  7. import com.facebook.react.views.text.ReactTextView
  8. import com.reactnativenavigation.parse.SharedElementTransitionOptions
  9. import com.reactnativenavigation.utils.TextViewUtils
  10. import com.reactnativenavigation.utils.ViewUtils
  11. import com.shazam.android.widget.text.reflow.ReflowTextAnimatorHelper
  12. class TextChangeAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactTextView>(from, to) {
  13. override fun shouldAnimateProperty(fromChild: ReactTextView, toChild: ReactTextView): Boolean {
  14. val fromXy = ViewUtils.getLocationOnScreen(from)
  15. val toXy = ViewUtils.getLocationOnScreen(to)
  16. return TextViewUtils.getTextSize(fromChild) != TextViewUtils.getTextSize(toChild) ||
  17. !fromXy.equals(toXy.x, toXy.y)
  18. }
  19. override fun create(options: SharedElementTransitionOptions): Animator {
  20. return ReflowTextAnimatorHelper.Builder(from as TextView, to as TextView)
  21. .calculateDuration(false)
  22. .setBoundsCalculator { view: View ->
  23. val loc = IntArray(2)
  24. view.getLocationInWindow(loc)
  25. val x = loc[0]
  26. val y = if (view == to) (to.layoutParams as ViewGroup.MarginLayoutParams).topMargin else loc[1]
  27. Rect(
  28. x,
  29. y,
  30. x + view.width,
  31. y + view.height
  32. )
  33. }
  34. .setTextColorGetter {
  35. TextViewUtils.getTextColor(it)
  36. }
  37. .buildAnimator()
  38. .setDuration(options.getDuration())
  39. }
  40. }