react-native-navigation的迁移库

BackgroundColorAnimator.kt 1.4KB

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.ViewGroup
  6. import com.facebook.react.views.text.ReactTextView
  7. import com.facebook.react.views.view.ReactViewBackgroundDrawable
  8. import com.reactnativenavigation.parse.SharedElementTransitionOptions
  9. import com.reactnativenavigation.utils.ColorUtils
  10. import com.reactnativenavigation.utils.ViewUtils
  11. class BackgroundColorAnimator(from: View, to: View) : PropertyAnimatorCreator<ViewGroup>(from, to) {
  12. override fun shouldAnimateProperty(fromChild: ViewGroup, toChild: ViewGroup): Boolean {
  13. return fromChild.background is ReactViewBackgroundDrawable &&
  14. toChild.background is ReactViewBackgroundDrawable && (fromChild.background as ReactViewBackgroundDrawable).color != (toChild.background as ReactViewBackgroundDrawable).color
  15. }
  16. override fun excludedViews() = listOf(ReactTextView::class.java)
  17. override fun create(options: SharedElementTransitionOptions): Animator {
  18. return ObjectAnimator.ofObject(
  19. BackgroundColorEvaluator(to.background as ReactViewBackgroundDrawable),
  20. ColorUtils.colorToLAB(ViewUtils.getBackgroundColor(from)),
  21. ColorUtils.colorToLAB(ViewUtils.getBackgroundColor(to))
  22. ).setDuration(options.getDuration())
  23. }
  24. }