react-native-navigation的迁移库

SharedElementTransition.kt 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.reactnativenavigation.views.element
  2. import android.animation.AnimatorSet
  3. import android.view.View
  4. import com.reactnativenavigation.parse.SharedElementTransitionOptions
  5. import com.reactnativenavigation.viewcontrollers.ViewController
  6. import com.reactnativenavigation.views.element.animators.*
  7. class SharedElementTransition(appearing: ViewController<*>, private val options: SharedElementTransitionOptions) : Transition() {
  8. val fromId: String = options.fromId.get()
  9. val toId: String = options.toId.get()
  10. lateinit var from: View
  11. lateinit var to: View
  12. override var viewController: ViewController<*> = appearing
  13. override val view: View
  14. get() = to
  15. override val topInset: Int
  16. get() = viewController.topInset
  17. fun isValid(): Boolean = this::from.isInitialized
  18. override fun createAnimators(): AnimatorSet {
  19. val animators = animators()
  20. .filter { it.shouldAnimateProperty() }
  21. .map { it.create(options) }
  22. val set = AnimatorSet()
  23. set.playTogether(animators)
  24. return set
  25. }
  26. private fun animators(): List<PropertyAnimatorCreator<*>> {
  27. return listOf(
  28. XAnimator(from, to),
  29. YAnimator(from, to),
  30. MatrixAnimator(from, to),
  31. ScaleXAnimator(from, to),
  32. ScaleYAnimator(from, to),
  33. BackgroundColorAnimator(from, to),
  34. TextChangeAnimator(from, to)
  35. )
  36. }
  37. }