react-native-navigation的迁移库

CollapsingSingleScreen.java 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.reactnativenavigation.screens;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.widget.ScrollView;
  4. import com.reactnativenavigation.params.ScreenParams;
  5. import com.reactnativenavigation.views.CollapsingContentView;
  6. import com.reactnativenavigation.views.LeftButtonOnClickListener;
  7. import com.reactnativenavigation.views.collapsingToolbar.CollapseAmount;
  8. import com.reactnativenavigation.views.collapsingToolbar.CollapseCalculator;
  9. import com.reactnativenavigation.views.collapsingToolbar.CollapsingTopBar;
  10. import com.reactnativenavigation.views.collapsingToolbar.CollapsingView;
  11. import com.reactnativenavigation.views.collapsingToolbar.CollapsingViewMeasurer;
  12. import com.reactnativenavigation.views.collapsingToolbar.OnScrollListener;
  13. import com.reactnativenavigation.views.collapsingToolbar.OnScrollViewAddedListener;
  14. import com.reactnativenavigation.views.collapsingToolbar.ScrollListener;
  15. import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBehaviour;
  16. public class CollapsingSingleScreen extends SingleScreen {
  17. public CollapsingSingleScreen(AppCompatActivity activity, ScreenParams screenParams, LeftButtonOnClickListener titleBarBarBackButtonListener) {
  18. super(activity, screenParams, titleBarBarBackButtonListener);
  19. }
  20. @Override
  21. public void destroy() {
  22. super.destroy();
  23. ((CollapsingContentView) contentView).destroy();
  24. }
  25. @Override
  26. protected void createTopBar() {
  27. final CollapsingTopBar topBar = new CollapsingTopBar(getContext(), styleParams.collapsingTopBarParams);
  28. topBar.setScrollListener(getScrollListener(topBar));
  29. this.topBar = topBar;
  30. }
  31. @Override
  32. protected void createContent() {
  33. contentView = new CollapsingContentView(getContext(), screenParams.screenId, screenParams.navigationParams);
  34. setViewMeasurer();
  35. setupCollapseDetection((CollapsingTopBar) topBar);
  36. addView(contentView, createLayoutParams());
  37. }
  38. private void setViewMeasurer() {
  39. if (screenParams.styleParams.drawScreenBelowTopBar || screenParams.styleParams.drawScreenAboveBottomTabs) {
  40. contentView.setViewMeasurer(new CollapsingViewMeasurer((CollapsingTopBar) topBar, this, screenParams.styleParams));
  41. }
  42. }
  43. private void setupCollapseDetection(final CollapsingTopBar topBar) {
  44. ((CollapsingContentView) contentView).setupCollapseDetection(getScrollListener(topBar), new OnScrollViewAddedListener() {
  45. @Override
  46. public void onScrollViewAdded(ScrollView scrollView) {
  47. topBar.onScrollViewAdded(scrollView);
  48. }
  49. });
  50. }
  51. private ScrollListener getScrollListener(final CollapsingTopBar topBar) {
  52. return new ScrollListener(new CollapseCalculator(topBar, getCollapseBehaviour()),
  53. new OnScrollListener() {
  54. @Override
  55. public void onScroll(CollapseAmount amount) {
  56. if (screenParams.styleParams.drawScreenBelowTopBar) {
  57. ((CollapsingView) contentView).collapse(amount);
  58. }
  59. topBar.collapse(amount);
  60. }
  61. @Override
  62. public void onFling(CollapseAmount amount) {
  63. if (screenParams.styleParams.drawScreenBelowTopBar) {
  64. ((CollapsingView) contentView).collapse(amount);
  65. }
  66. topBar.collapse(amount);
  67. }
  68. },
  69. getCollapseBehaviour()
  70. );
  71. }
  72. private CollapseBehaviour getCollapseBehaviour() {
  73. return screenParams.styleParams.collapsingTopBarParams.collapseBehaviour;
  74. }
  75. }