react-native-navigation的迁移库

BottomTabOptions.java 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.reactnativenavigation.parse;
  2. import android.graphics.Typeface;
  3. import android.support.annotation.Nullable;
  4. import com.reactnativenavigation.parse.params.Color;
  5. import com.reactnativenavigation.parse.params.NullColor;
  6. import com.reactnativenavigation.parse.params.NullNumber;
  7. import com.reactnativenavigation.parse.params.NullText;
  8. import com.reactnativenavigation.parse.params.Number;
  9. import com.reactnativenavigation.parse.params.Text;
  10. import com.reactnativenavigation.parse.parsers.ColorParser;
  11. import com.reactnativenavigation.parse.parsers.NumberParser;
  12. import com.reactnativenavigation.parse.parsers.TextParser;
  13. import com.reactnativenavigation.utils.TypefaceLoader;
  14. import org.json.JSONObject;
  15. public class BottomTabOptions {
  16. public static BottomTabOptions parse(TypefaceLoader typefaceManager, JSONObject json) {
  17. BottomTabOptions options = new BottomTabOptions();
  18. if (json == null) return options;
  19. options.text = TextParser.parse(json, "text");
  20. options.textColor = ColorParser.parse(json, "textColor");
  21. options.selectedTextColor = ColorParser.parse(json, "selectedTextColor");
  22. if (json.has("icon")) options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
  23. options.iconColor = ColorParser.parse(json, "iconColor");
  24. options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
  25. options.badge = TextParser.parse(json, "badge");
  26. options.testId = TextParser.parse(json, "testID");
  27. options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", ""));
  28. options.fontSize = NumberParser.parse(json, "fontSize");
  29. options.selectedFontSize = NumberParser.parse(json, "selectedFontSize");
  30. return options;
  31. }
  32. public Text text = new NullText();
  33. public Color textColor = new NullColor();
  34. public Color selectedTextColor = new NullColor();
  35. public Text icon = new NullText();
  36. public Color iconColor = new NullColor();
  37. public Color selectedIconColor = new NullColor();
  38. public Text testId = new NullText();
  39. public Text badge = new NullText();
  40. public Number fontSize = new NullNumber();
  41. public Number selectedFontSize = new NullNumber();
  42. @Nullable public Typeface fontFamily;
  43. void mergeWith(final BottomTabOptions other) {
  44. if (other.text.hasValue()) text = other.text;
  45. if (other.textColor.hasValue()) textColor = other.textColor;
  46. if (other.selectedTextColor.hasValue()) selectedTextColor = other.selectedTextColor;
  47. if (other.icon.hasValue()) icon = other.icon;
  48. if (other.iconColor.hasValue()) iconColor = other.iconColor;
  49. if (other.selectedIconColor.hasValue()) selectedIconColor = other.selectedIconColor;
  50. if (other.badge.hasValue()) badge = other.badge;
  51. if (other.testId.hasValue()) testId = other.testId;
  52. if (other.fontSize.hasValue()) fontSize = other.fontSize;
  53. if (other.selectedFontSize.hasValue()) selectedFontSize = other.selectedFontSize;
  54. if (other.fontFamily != null) fontFamily = other.fontFamily;
  55. }
  56. void mergeWithDefault(final BottomTabOptions defaultOptions) {
  57. if (!text.hasValue()) text = defaultOptions.text;
  58. if (!textColor.hasValue()) textColor = defaultOptions.textColor;
  59. if (!selectedTextColor.hasValue()) selectedTextColor = defaultOptions.selectedTextColor;
  60. if (!icon.hasValue()) icon = defaultOptions.icon;
  61. if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
  62. if (!selectedIconColor.hasValue()) selectedIconColor = defaultOptions.selectedIconColor;
  63. if (!badge.hasValue()) badge = defaultOptions.badge;
  64. if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
  65. if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
  66. if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
  67. }
  68. }