react-native-navigation的迁移库

BackgroundColorAnimator.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.reactnativenavigation.views.element.animators;
  2. import android.animation.Animator;
  3. import android.animation.ObjectAnimator;
  4. import android.view.ViewGroup;
  5. import com.facebook.react.views.text.ReactTextView;
  6. import com.facebook.react.views.view.ReactViewBackgroundDrawable;
  7. import com.reactnativenavigation.utils.ColorUtils;
  8. import com.reactnativenavigation.utils.ViewUtils;
  9. import com.reactnativenavigation.views.element.Element;
  10. import java.util.Collections;
  11. import java.util.List;
  12. public class BackgroundColorAnimator extends PropertyAnimatorCreator<ViewGroup> {
  13. public BackgroundColorAnimator(Element from, Element to) {
  14. super(from, to);
  15. }
  16. @Override
  17. public boolean shouldAnimateProperty(ViewGroup fromChild, ViewGroup toChild) {
  18. return fromChild.getBackground() instanceof ReactViewBackgroundDrawable &&
  19. toChild.getBackground() instanceof ReactViewBackgroundDrawable &&
  20. ((ReactViewBackgroundDrawable) fromChild.getBackground()).getColor() != ((ReactViewBackgroundDrawable) toChild.getBackground()).getColor();
  21. }
  22. @Override
  23. protected List<Class> excludedViews() {
  24. return Collections.singletonList(ReactTextView.class);
  25. }
  26. @Override
  27. public Animator create() {
  28. return ObjectAnimator.ofObject(
  29. to,
  30. "backgroundColor",
  31. new LabColorEvaluator(),
  32. ColorUtils.colorToLAB(ViewUtils.getBackgroundColor(from.getChild())),
  33. ColorUtils.colorToLAB(ViewUtils.getBackgroundColor(to.getChild()))
  34. );
  35. }
  36. }