react-native-navigation的迁移库

LayoutOptions.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.reactnativenavigation.parse;
  2. import com.reactnativenavigation.parse.params.Color;
  3. import com.reactnativenavigation.parse.params.NullColor;
  4. import com.reactnativenavigation.parse.params.NullNumber;
  5. import com.reactnativenavigation.parse.params.Number;
  6. import com.reactnativenavigation.parse.parsers.ColorParser;
  7. import com.reactnativenavigation.parse.parsers.NumberParser;
  8. import org.json.JSONObject;
  9. public class LayoutOptions {
  10. public static LayoutOptions parse(JSONObject json) {
  11. LayoutOptions result = new LayoutOptions();
  12. if (json == null) return result;
  13. result.backgroundColor = ColorParser.parse(json, "backgroundColor");
  14. result.topMargin = NumberParser.parse(json, "topMargin");
  15. result.orientation = OrientationOptions.parse(json);
  16. return result;
  17. }
  18. public Color backgroundColor = new NullColor();
  19. public Number topMargin = new NullNumber();
  20. public OrientationOptions orientation = new OrientationOptions();
  21. public void mergeWith(LayoutOptions other) {
  22. if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
  23. if (other.topMargin.hasValue()) topMargin = other.topMargin;
  24. if (other.orientation.hasValue()) orientation = other.orientation;
  25. }
  26. public void mergeWithDefault(LayoutOptions defaultOptions) {
  27. if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
  28. if (!topMargin.hasValue()) topMargin = defaultOptions.topMargin;
  29. if (!orientation.hasValue()) orientation = defaultOptions.orientation;
  30. }
  31. }