react-native-navigation的迁移库

MatrixAnimator.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.reactnativenavigation.views.element.animators;
  2. import android.animation.Animator;
  3. import android.animation.AnimatorSet;
  4. import android.animation.ObjectAnimator;
  5. import android.graphics.Rect;
  6. import android.view.View;
  7. import com.facebook.drawee.drawable.ScalingUtils;
  8. import com.facebook.drawee.generic.GenericDraweeHierarchy;
  9. import com.facebook.drawee.view.DraweeView;
  10. import com.facebook.react.views.image.ReactImageView;
  11. import com.reactnativenavigation.views.element.Element;
  12. import static com.reactnativenavigation.utils.ViewUtils.areDimensionsEqual;
  13. public class MatrixAnimator extends PropertyAnimatorCreator<ReactImageView> {
  14. public MatrixAnimator(Element from, Element to) {
  15. super(from, to);
  16. }
  17. @Override
  18. public boolean shouldAnimateProperty(ReactImageView fromChild, ReactImageView toChild) {
  19. return !areDimensionsEqual(from.getChild(), to.getChild());
  20. }
  21. @Override
  22. public Animator create() {
  23. AnimatorSet set = new AnimatorSet();
  24. set.playTogether(clipBoundsAnimator(), imageTransformAnimator());
  25. return set;
  26. }
  27. private Animator clipBoundsAnimator() {
  28. Rect startDrawingRect = new Rect(); from.getDrawingRect(startDrawingRect);
  29. Rect endDrawingRect = new Rect(); to.getDrawingRect(endDrawingRect);
  30. return ObjectAnimator.ofObject(to,
  31. "clipBounds",
  32. new ClipBoundsEvaluator(),
  33. startDrawingRect,
  34. endDrawingRect);
  35. }
  36. private Animator imageTransformAnimator() {
  37. ScalingUtils.InterpolatingScaleType ist = new ScalingUtils.InterpolatingScaleType(
  38. getScaleType(from.getChild()),
  39. getScaleType(to.getChild()),
  40. calculateBounds(from.getChild()),
  41. calculateBounds(to.getChild())
  42. );
  43. ((DraweeView<GenericDraweeHierarchy>) to.getChild()).getHierarchy().setActualImageScaleType(ist);
  44. return ObjectAnimator.ofFloat(to, "matrixTransform", 0, 1);
  45. }
  46. private ScalingUtils.ScaleType getScaleType(View child) {
  47. return ((DraweeView<GenericDraweeHierarchy>) child).getHierarchy().getActualImageScaleType();
  48. }
  49. private Rect calculateBounds(View view) {
  50. return new Rect(0, 0, view.getWidth(), view.getHeight());
  51. }
  52. }