react-native-navigation的迁移库

PropertyAnimatorCreator.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.reactnativenavigation.views.element.animators;
  2. import android.animation.Animator;
  3. import android.animation.AnimatorListenerAdapter;
  4. import androidx.annotation.CallSuper;
  5. import android.view.ViewGroup;
  6. import com.reactnativenavigation.parse.Transition;
  7. import com.reactnativenavigation.views.element.Element;
  8. import java.lang.reflect.ParameterizedType;
  9. import java.util.Collections;
  10. import java.util.List;
  11. public abstract class PropertyAnimatorCreator<T> {
  12. protected Element from;
  13. protected Element to;
  14. PropertyAnimatorCreator(Element from, Element to) {
  15. this.from = from;
  16. this.to = to;
  17. }
  18. @CallSuper
  19. public boolean shouldAnimateProperty() {
  20. Class<T> type = getChildClass();
  21. return type.isInstance(from.getChild()) &&
  22. type.isInstance(to.getChild()) &&
  23. !excludedViews().contains(from.getChild().getClass()) &&
  24. !excludedViews().contains(to.getChild().getClass()) &&
  25. shouldAnimateProperty((T) from.getChild(), (T) to.getChild());
  26. }
  27. protected abstract boolean shouldAnimateProperty(T fromChild, T toChild);
  28. protected List<Class> excludedViews() {
  29. return Collections.EMPTY_LIST;
  30. }
  31. public Animator create(Transition transition) {
  32. Animator animator = create().setDuration(transition.duration.get());
  33. animator.addListener(new AnimatorListenerAdapter() {
  34. private final boolean originalClipChildren = ((ViewGroup) to.getParent()).getClipChildren();
  35. @Override
  36. public void onAnimationStart(Animator animation) {
  37. ((ViewGroup) to.getParent()).setClipChildren(false);
  38. }
  39. @Override
  40. public void onAnimationEnd(Animator animation) {
  41. ((ViewGroup) to.getParent()).setClipChildren(originalClipChildren);
  42. }
  43. });
  44. return animator;
  45. }
  46. protected abstract Animator create();
  47. private Class<T> getChildClass() {
  48. return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  49. }
  50. }