react-native-navigation的迁移库

BackButton.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.reactnativenavigation.parse;
  2. import com.reactnativenavigation.parse.params.Bool;
  3. import com.reactnativenavigation.parse.params.Button;
  4. import com.reactnativenavigation.parse.params.NullBool;
  5. import com.reactnativenavigation.parse.parsers.BoolParser;
  6. import com.reactnativenavigation.parse.parsers.ColorParser;
  7. import com.reactnativenavigation.parse.parsers.TextParser;
  8. import com.reactnativenavigation.react.Constants;
  9. import org.json.JSONObject;
  10. public class BackButton extends Button {
  11. public static BackButton parse(JSONObject json) {
  12. BackButton result = new BackButton();
  13. if (json == null) return result;
  14. result.hasValue = true;
  15. result.visible = BoolParser.parse(json, "visible");
  16. if (json.has("icon")) result.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
  17. result.id = json.optString("id", Constants.BACK_BUTTON_ID);
  18. result.enabled = BoolParser.parse(json, "enabled");
  19. result.disableIconTint = BoolParser.parse(json, "disableIconTint");
  20. result.color = ColorParser.parse(json, "color");
  21. result.disabledColor = ColorParser.parse(json, "disabledColor");
  22. result.testId = TextParser.parse(json, "testID");
  23. return result;
  24. }
  25. BackButton() {
  26. id = Constants.BACK_BUTTON_ID;
  27. }
  28. public Bool visible = new NullBool();
  29. private boolean hasValue;
  30. public boolean hasValue() {
  31. return hasValue;
  32. }
  33. public void mergeWith(BackButton other) {
  34. if (other.icon.hasValue()) icon = other.icon;
  35. if (other.visible.hasValue()) visible = other.visible;
  36. if (other.color.hasValue()) color = other.color;
  37. if (other.disabledColor.hasValue()) disabledColor = other.disabledColor;
  38. if (other.disableIconTint.hasValue()) disableIconTint = other.disableIconTint;
  39. if (other.enabled.hasValue()) enabled = other.enabled;
  40. if (other.testId.hasValue()) testId = other.testId;
  41. }
  42. void mergeWithDefault(final BackButton defaultOptions) {
  43. if (!icon.hasValue()) icon = defaultOptions.icon;
  44. if (!visible.hasValue()) visible = defaultOptions.visible;
  45. if (!color.hasValue()) color = defaultOptions.color;
  46. if (!disabledColor.hasValue()) disabledColor = defaultOptions.disabledColor;
  47. if (!disableIconTint.hasValue()) disableIconTint = defaultOptions.disableIconTint;
  48. if (!enabled.hasValue()) enabled = defaultOptions.enabled;
  49. if (!testId.hasValue()) testId = defaultOptions.testId;
  50. }
  51. public void setVisible() {
  52. visible = new Bool(true);
  53. hasValue = true;
  54. }
  55. }