react-native-navigation的迁移库

CollapsingContentView.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.reactnativenavigation.views;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import android.support.annotation.Nullable;
  5. import android.view.MotionEvent;
  6. import android.view.View;
  7. import com.reactnativenavigation.params.NavigationParams;
  8. import com.reactnativenavigation.views.collapsingToolbar.CollapseAmount;
  9. import com.reactnativenavigation.views.collapsingToolbar.CollapsingView;
  10. import com.reactnativenavigation.views.collapsingToolbar.CollapsingViewMeasurer;
  11. import com.reactnativenavigation.views.collapsingToolbar.OnScrollViewAddedListener;
  12. import com.reactnativenavigation.views.collapsingToolbar.ScrollListener;
  13. import com.reactnativenavigation.views.collapsingToolbar.ScrollViewDelegate;
  14. import com.reactnativenavigation.views.collapsingToolbar.ViewCollapser;
  15. import com.reactnativenavigation.views.utils.ScrollViewDetector;
  16. @SuppressLint("ViewConstructor")
  17. public class CollapsingContentView extends ContentView implements CollapsingView {
  18. private @Nullable ScrollViewDelegate scrollViewDelegate;
  19. private @Nullable ScrollViewDetector scrollViewDetector;
  20. private final ViewCollapser viewCollapser;
  21. public CollapsingContentView(Context context, String screenId, NavigationParams navigationParams) {
  22. super(context, screenId, navigationParams);
  23. viewCollapser = new ViewCollapser(this);
  24. }
  25. public void setupCollapseDetection(ScrollListener scrollListener, OnScrollViewAddedListener onScrollViewAddedListener) {
  26. scrollViewDelegate = new ScrollViewDelegate(scrollListener);
  27. scrollViewDetector = new ScrollViewDetector(this, onScrollViewAddedListener, scrollViewDelegate);
  28. }
  29. @Override
  30. public boolean dispatchTouchEvent(MotionEvent ev) {
  31. if (scrollViewDelegate != null && scrollViewDelegate.hasScrollView()) {
  32. boolean consumed = scrollViewDelegate.didInterceptTouchEvent(ev);
  33. if (consumed) {
  34. return true;
  35. }
  36. }
  37. return super.dispatchTouchEvent(ev);
  38. }
  39. @Override
  40. public void onViewAdded(final View child) {
  41. super.onViewAdded(child);
  42. if (scrollViewDetector != null) {
  43. scrollViewDetector.findScrollView(child);
  44. }
  45. }
  46. @Override
  47. public void collapse(CollapseAmount amount) {
  48. viewCollapser.collapse(amount);
  49. }
  50. public void destroy() {
  51. if (scrollViewDetector != null) {
  52. scrollViewDetector.destroy();
  53. }
  54. if (scrollViewDelegate != null) {
  55. scrollViewDelegate.destroy();
  56. }
  57. }
  58. @Override
  59. public float getFinalCollapseValue() {
  60. return ((CollapsingViewMeasurer) viewMeasurer).getFinalCollapseValue();
  61. }
  62. @Override
  63. public float getCurrentCollapseValue() {
  64. return getTranslationY();
  65. }
  66. @Override
  67. public View asView() {
  68. return this;
  69. }
  70. }