react-native-navigation的迁移库

TopBarOptions.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.reactnativenavigation.parse;
  2. import android.util.Log;
  3. import com.reactnativenavigation.BuildConfig;
  4. import com.reactnativenavigation.parse.params.Bool;
  5. import com.reactnativenavigation.parse.params.Color;
  6. import com.reactnativenavigation.parse.params.Fraction;
  7. import com.reactnativenavigation.parse.params.NullBool;
  8. import com.reactnativenavigation.parse.params.NullColor;
  9. import com.reactnativenavigation.parse.params.NullFraction;
  10. import com.reactnativenavigation.parse.params.NullNumber;
  11. import com.reactnativenavigation.parse.params.NullText;
  12. import com.reactnativenavigation.parse.params.Number;
  13. import com.reactnativenavigation.parse.params.Text;
  14. import com.reactnativenavigation.parse.parsers.BoolParser;
  15. import com.reactnativenavigation.parse.parsers.ColorParser;
  16. import com.reactnativenavigation.parse.parsers.FractionParser;
  17. import com.reactnativenavigation.parse.parsers.NumberParser;
  18. import com.reactnativenavigation.parse.parsers.TextParser;
  19. import com.reactnativenavigation.utils.TypefaceLoader;
  20. import org.json.JSONObject;
  21. public class TopBarOptions {
  22. public static TopBarOptions parse(TypefaceLoader typefaceLoader, JSONObject json) {
  23. TopBarOptions options = new TopBarOptions();
  24. if (json == null) return options;
  25. options.title = TitleOptions.parse(typefaceLoader, json.optJSONObject("title"));
  26. options.subtitle = SubtitleOptions.parse(typefaceLoader, json.optJSONObject("subtitle"));
  27. options.background = TopBarBackgroundOptions.parse(json.optJSONObject("background"));
  28. options.visible = BoolParser.parse(json, "visible");
  29. options.animate = BoolParser.parse(json,"animate");
  30. options.hideOnScroll = BoolParser.parse(json,"hideOnScroll");
  31. options.drawBehind = BoolParser.parse(json,"drawBehind");
  32. options.testId = TextParser.parse(json, "testID");
  33. options.height = NumberParser.parse(json, "height");
  34. options.borderColor = ColorParser.parse(json, "borderColor");
  35. options.borderHeight = FractionParser.parse(json, "borderHeight");
  36. options.elevation = FractionParser.parse(json, "elevation");
  37. options.buttons = TopBarButtons.parse(typefaceLoader, json);
  38. options.validate();
  39. return options;
  40. }
  41. public TitleOptions title = new TitleOptions();
  42. public SubtitleOptions subtitle = new SubtitleOptions();
  43. public TopBarButtons buttons = new TopBarButtons();
  44. public Text testId = new NullText();
  45. public TopBarBackgroundOptions background = new TopBarBackgroundOptions();
  46. public Bool visible = new NullBool();
  47. public Bool animate = new NullBool();
  48. public Bool hideOnScroll = new NullBool();
  49. public Bool drawBehind = new NullBool();
  50. public Number height = new NullNumber();
  51. public Fraction elevation = new NullFraction();
  52. public Fraction borderHeight = new NullFraction();
  53. public Color borderColor = new NullColor();
  54. void mergeWith(final TopBarOptions other) {
  55. title.mergeWith(other.title);
  56. subtitle.mergeWith(other.subtitle);
  57. background.mergeWith(other.background);
  58. buttons.mergeWith(other.buttons);
  59. if (other.testId.hasValue()) testId = other.testId;
  60. if (other.visible.hasValue()) visible = other.visible;
  61. if (other.animate.hasValue()) animate = other.animate;
  62. if (other.hideOnScroll.hasValue()) hideOnScroll = other.hideOnScroll;
  63. if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
  64. if (other.height.hasValue()) height = other.height;
  65. if (other.borderHeight.hasValue()) borderHeight = other.borderHeight;
  66. if (other.borderColor.hasValue()) borderColor = other.borderColor;
  67. if (other.elevation.hasValue()) elevation = other.elevation;
  68. validate();
  69. }
  70. void mergeWithDefault(TopBarOptions defaultOptions) {
  71. title.mergeWithDefault(defaultOptions.title);
  72. subtitle.mergeWithDefault(defaultOptions.subtitle);
  73. background.mergeWithDefault(defaultOptions.background);
  74. buttons.mergeWithDefault(defaultOptions.buttons);
  75. if (!visible.hasValue()) visible = defaultOptions.visible;
  76. if (!animate.hasValue()) animate = defaultOptions.animate;
  77. if (!hideOnScroll.hasValue()) hideOnScroll = defaultOptions.hideOnScroll;
  78. if (!drawBehind.hasValue()) drawBehind = defaultOptions.drawBehind;
  79. if (!testId.hasValue()) testId = defaultOptions.testId;
  80. if (!height.hasValue()) height = defaultOptions.height;
  81. if (!borderHeight.hasValue()) borderHeight = defaultOptions.borderHeight;
  82. if (!borderColor.hasValue()) borderColor = defaultOptions.borderColor;
  83. if (!elevation.hasValue()) elevation = defaultOptions.elevation;
  84. validate();
  85. }
  86. private void validate() {
  87. if (title.component.hasValue() && (title.text.hasValue() || subtitle.text.hasValue())) {
  88. if (BuildConfig.DEBUG) Log.w("RNN", "A screen can't use both text and component - clearing text.");
  89. title.text = new NullText();
  90. subtitle.text = new NullText();
  91. }
  92. }
  93. }