react-native-navigation的迁移库

CollapsingViewMeasurer.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.reactnativenavigation.views.collapsingToolbar;
  2. import com.reactnativenavigation.params.StyleParams;
  3. import com.reactnativenavigation.screens.Screen;
  4. import com.reactnativenavigation.utils.ViewUtils;
  5. import com.reactnativenavigation.views.utils.ViewMeasurer;
  6. public class CollapsingViewMeasurer extends ViewMeasurer {
  7. int collapsedTopBarHeight;
  8. private float finalCollapseValue;
  9. int screenHeight;
  10. int bottomTabsHeight = 0;
  11. boolean bottomTabsHidden;
  12. public CollapsingViewMeasurer(CollapsingTopBar topBar, Screen screen, StyleParams styleParams) {
  13. this(topBar, screen);
  14. bottomTabsHidden = styleParams.bottomTabsHidden;
  15. bottomTabsHeight = (int) ViewUtils.convertDpToPixel(56);
  16. }
  17. public CollapsingViewMeasurer(final CollapsingTopBar topBar, final Screen collapsingSingleScreen) {
  18. ViewUtils.runOnPreDraw(topBar, new Runnable() {
  19. @Override
  20. public void run() {
  21. collapsedTopBarHeight = topBar.getCollapsedHeight();
  22. finalCollapseValue = topBar.getFinalCollapseValue();
  23. }
  24. });
  25. ViewUtils.runOnPreDraw(collapsingSingleScreen, new Runnable() {
  26. @Override
  27. public void run() {
  28. screenHeight = collapsingSingleScreen.getMeasuredHeight();
  29. }
  30. });
  31. }
  32. public float getFinalCollapseValue() {
  33. return finalCollapseValue;
  34. }
  35. @Override
  36. public int getMeasuredHeight(int heightMeasureSpec) {
  37. return screenHeight - collapsedTopBarHeight + (bottomTabsHidden ? bottomTabsHeight : 0);
  38. }
  39. }