react-native-navigation的迁移库

TopTabsOptions.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.reactnativenavigation.parse;
  2. import android.support.annotation.NonNull;
  3. import android.support.annotation.Nullable;
  4. import com.reactnativenavigation.parse.params.Bool;
  5. import com.reactnativenavigation.parse.params.Color;
  6. import com.reactnativenavigation.parse.params.NullBool;
  7. import com.reactnativenavigation.parse.params.NullColor;
  8. import com.reactnativenavigation.parse.params.NullNumber;
  9. import com.reactnativenavigation.parse.params.Number;
  10. import com.reactnativenavigation.parse.parsers.BoolParser;
  11. import com.reactnativenavigation.parse.parsers.ColorParser;
  12. import com.reactnativenavigation.parse.parsers.NumberParser;
  13. import org.json.JSONObject;
  14. public class TopTabsOptions {
  15. @NonNull public Color selectedTabColor = new NullColor();
  16. @NonNull public Color unselectedTabColor = new NullColor();
  17. @NonNull public Number fontSize = new NullNumber();
  18. @NonNull public Bool visible = new NullBool();
  19. @NonNull public Number height = new NullNumber();
  20. public static TopTabsOptions parse(@Nullable JSONObject json) {
  21. TopTabsOptions result = new TopTabsOptions();
  22. if (json == null) return result;
  23. result.selectedTabColor = ColorParser.parse(json, "selectedTabColor");
  24. result.unselectedTabColor = ColorParser.parse(json, "unselectedTabColor");
  25. result.fontSize = NumberParser.parse(json, "fontSize");
  26. result.visible = BoolParser.parse(json, "visible");
  27. result.height = NumberParser.parse(json, "height");
  28. return result;
  29. }
  30. void mergeWith(TopTabsOptions other) {
  31. if (other.selectedTabColor.hasValue()) selectedTabColor = other.selectedTabColor;
  32. if (other.unselectedTabColor.hasValue()) unselectedTabColor = other.unselectedTabColor;
  33. if (other.fontSize.hasValue()) fontSize = other.fontSize;
  34. if (other.visible.hasValue()) visible = other.visible;
  35. if (other.height.hasValue()) height = other.height;
  36. }
  37. void mergeWithDefault(TopTabsOptions defaultOptions) {
  38. if (!selectedTabColor.hasValue()) selectedTabColor = defaultOptions.selectedTabColor;
  39. if (!unselectedTabColor.hasValue()) unselectedTabColor = defaultOptions.unselectedTabColor;
  40. if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
  41. if (!visible.hasValue()) visible = defaultOptions.visible;
  42. if (!height.hasValue()) height = defaultOptions.height;
  43. }
  44. }