react-native-navigation的迁移库

ClipBoundsEvaluator.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.reactnativenavigation.views.element.animators;
  2. import android.animation.TypeEvaluator;
  3. import android.graphics.Rect;
  4. public class ClipBoundsEvaluator implements TypeEvaluator<Rect> {
  5. private int fromWidth;
  6. private int fromHeight;
  7. private int toWidth;
  8. private int toHeight;
  9. private final Rect result = new Rect();
  10. @Override
  11. public Rect evaluate(float ratio, Rect from, Rect to) {
  12. sync(from, to);
  13. if (toHeight == fromHeight ) {
  14. result.bottom = toHeight;
  15. } else {
  16. if (toHeight > fromHeight) {
  17. result.bottom = (int) (toHeight - (toHeight - fromHeight) * (1 - ratio));
  18. } else {
  19. result.bottom = (int) (toHeight + (fromHeight - toHeight) * (1 - ratio));
  20. }
  21. }
  22. if (toWidth == fromWidth) {
  23. result.right = toWidth;
  24. } else {
  25. if (toWidth > fromWidth) {
  26. result.right = (int) (toWidth - (toWidth - fromWidth) * (1 - ratio));
  27. } else {
  28. result.right = (int) (toWidth + (fromWidth - toWidth) * (1 - ratio));
  29. }
  30. }
  31. return result;
  32. }
  33. private void sync(Rect from, Rect to) {
  34. fromWidth = from.right;
  35. fromHeight = from.bottom;
  36. toWidth = to.right;
  37. toHeight = to.bottom;
  38. }
  39. }