react-native-navigation的迁移库

PropertyAnimatorCreator.kt 1.1KB

123456789101112131415161718192021222324252627
  1. package com.reactnativenavigation.views.element.animators
  2. import android.animation.Animator
  3. import android.view.View
  4. import androidx.annotation.CallSuper
  5. import com.reactnativenavigation.parse.SharedElementTransitionOptions
  6. import java.lang.reflect.ParameterizedType
  7. abstract class PropertyAnimatorCreator<T : View> internal constructor(protected var from: View, protected var to: View) {
  8. @CallSuper
  9. fun shouldAnimateProperty(): Boolean {
  10. val type = childClass
  11. return type.isInstance(from) &&
  12. type.isInstance(to) &&
  13. !excludedViews().contains(from.javaClass) &&
  14. !excludedViews().contains(to.javaClass) &&
  15. shouldAnimateProperty(from as T, to as T)
  16. }
  17. protected abstract fun shouldAnimateProperty(fromChild: T, toChild: T): Boolean
  18. protected open fun excludedViews() = emptyList<Class<*>>()
  19. abstract fun create(options: SharedElementTransitionOptions): Animator
  20. private val childClass: Class<T>
  21. get() = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<T>
  22. }