react-native-navigation的迁移库

CollapsingTopBarParamsParser.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.reactnativenavigation.params.parsers;
  2. import android.graphics.Color;
  3. import android.os.Bundle;
  4. import com.reactnativenavigation.params.CollapsingTopBarParams;
  5. import com.reactnativenavigation.params.StyleParams;
  6. import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBehaviour;
  7. import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseTitleBarBehaviour;
  8. import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseTopBarBehaviour;
  9. import com.reactnativenavigation.views.collapsingToolbar.behaviours.TitleBarHideOnScrollBehaviour;
  10. class CollapsingTopBarParamsParser extends Parser {
  11. private Bundle params;
  12. private boolean titleBarHideOnScroll;
  13. private boolean drawBelowTopBar;
  14. CollapsingTopBarParamsParser(Bundle params, boolean titleBarHideOnScroll, boolean drawBelowTopBar) {
  15. this.params = params;
  16. this.titleBarHideOnScroll = titleBarHideOnScroll;
  17. this.drawBelowTopBar = drawBelowTopBar;
  18. }
  19. public CollapsingTopBarParams parse() {
  20. if (!hasBackgroundImage() && !titleBarHideOnScroll) {
  21. return null;
  22. }
  23. CollapsingTopBarParams result = new CollapsingTopBarParams();
  24. if (hasBackgroundImage()) {
  25. result.imageUri = params.getString("collapsingToolBarImage");
  26. }
  27. result.scrimColor = getColor(params, "collapsingToolBarCollapsedColor", new StyleParams.Color(Color.WHITE));
  28. result.collapseBehaviour = getCollapseBehaviour();
  29. return result;
  30. }
  31. private CollapseBehaviour getCollapseBehaviour() {
  32. if (hasBackgroundImage()) {
  33. return new CollapseTopBarBehaviour();
  34. }
  35. if (titleBarHideOnScroll && drawBelowTopBar) {
  36. return new CollapseTitleBarBehaviour();
  37. }
  38. return new TitleBarHideOnScrollBehaviour();
  39. }
  40. private boolean hasBackgroundImage() {
  41. return params.containsKey("collapsingToolBarImage");
  42. }
  43. }