react-native-navigation的迁移库

Component.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.reactnativenavigation.parse;
  2. import com.reactnativenavigation.parse.params.NullText;
  3. import com.reactnativenavigation.parse.params.Text;
  4. import com.reactnativenavigation.parse.parsers.TextParser;
  5. import org.json.JSONObject;
  6. public class Component {
  7. public static Component parse(JSONObject json) {
  8. Component result = new Component();
  9. if (json == null) return result;
  10. result.name = TextParser.parse(json, "name");
  11. result.componentId = TextParser.parse(json, "componentId");
  12. result.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get(""));
  13. return result;
  14. }
  15. public Text name = new NullText();
  16. public Text componentId = new NullText();
  17. public Alignment alignment = Alignment.Default;
  18. void mergeWith(Component other) {
  19. if (other.componentId.hasValue()) componentId = other.componentId;
  20. if (other.name.hasValue()) name = other.name;
  21. if (other.alignment != Alignment.Default) alignment = other.alignment;
  22. }
  23. public void mergeWithDefault(Component defaultOptions) {
  24. if (!componentId.hasValue()) componentId = defaultOptions.componentId;
  25. if (!name.hasValue()) name = defaultOptions.name;
  26. if (alignment == Alignment.Default) alignment = defaultOptions.alignment;
  27. }
  28. public boolean hasValue() {
  29. return name.hasValue();
  30. }
  31. }