Skip to content

Commit

Permalink
fixing the bug that can't add child to a lview that has not been adde…
Browse files Browse the repository at this point in the history
…d to android viewgroup
  • Loading branch information
hsllany committed May 18, 2017
1 parent 814f332 commit d68aa72
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public void create() throws Exception {

String s6 = "red url(http://www.baidu.com) left center / auto auto";
Background r6 = Background.createOrChange("background", s6, null);
Assert.assertTrue(r6.getColor() == Color.RED);
Assert.assertTrue(r6.getRepeat() == Background.NO_REPEAT);
Assert.assertTrue(r6.getX() == 0);
Assert.assertTrue(r6.getY() == 0.5f);
Assert.assertTrue(r6.getUrl().equals("http://www.baidu.com"));
Assert.assertTrue(r6.getWidth() == 0);
Assert.assertTrue(r6.getWidthMode() == Background.AUTO);
Assert.assertTrue(r6.getHeight() == 0);
Assert.assertTrue(r6.getHeightMode() == Background.AUTO);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static InheritStyleStack computeInheritStyle(View view) {

StyleHandler viewStyleHandler = StyleHandlerFactory.get(view);
StyleHandler extraStyleHandler = StyleHandlerFactory.extraGet(view);
StyleHandler parentStyleHandler = StyleHandlerFactory.get(view);
StyleHandler parentStyleHandler = StyleHandlerFactory.parentGet(view);

LayoutStyleHandler parentLayoutAttr = null;
if (parentStyleHandler instanceof LayoutStyleHandler) {
Expand Down Expand Up @@ -236,7 +236,7 @@ public static View createView(AttrsSet.AttrsOwner owner, @NonNull DomElement tre

StyleHandler viewStyleHandler = StyleHandlerFactory.get(v);
StyleHandler extraStyleHandler = StyleHandlerFactory.extraGet(v);
StyleHandler parentStyleHandler = StyleHandlerFactory.get(v);
StyleHandler parentStyleHandler = StyleHandlerFactory.parentGet(v);

LayoutStyleHandler parentLayoutAttr = null;
if (parentStyleHandler instanceof LayoutStyleHandler) {
Expand Down Expand Up @@ -368,32 +368,29 @@ static View createAndroidViewGroup(@NonNull Context context, @Nullable String ty
LayoutParamsLazyCreator layoutParamsCreator) throws
ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
InstantiationException, IllegalAccessException {
View v;
Object displayObj = attrsSet.getStyle(owner, "display");
if (displayObj != null && displayObj instanceof String) {
String display = (String) displayObj;
switch (display) {
case Styles.VAL_DISPLAY_FLEX:
v = createAndroidView(context, "flexbox");
break;
case Styles.VAL_DISPLAY_ABSOLUTE:
v = createAndroidView(context, "box");
break;

case Styles.VAL_DISPLAY_BOX:
default:
v = createAndroidView(context, "linearbox");
break;
}
} else {
v = createAndroidView(context, "linearbox");
}

// set the <body> width to 100%
layoutParamsCreator.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParamsCreator.width = ViewGroup.LayoutParams.WRAP_CONTENT;

return v;
if (attrsSet != null) {
Object displayObj = attrsSet.getStyle(owner, "display");
if (displayObj != null && displayObj instanceof String) {
String display = (String) displayObj;
switch (display) {
case Styles.VAL_DISPLAY_FLEX:
return createAndroidView(context, "flexbox");
case Styles.VAL_DISPLAY_ABSOLUTE:
return createAndroidView(context, "box");

case Styles.VAL_DISPLAY_BOX:
default:
return createAndroidView(context, "linearbox");
}
}
}

return createAndroidView(context, "linearbox");
}

public static void renderStyle(Context context, final HNSandBoxContext sandBoxContext, View
Expand All @@ -403,7 +400,7 @@ public static void renderStyle(Context context, final HNSandBoxContext sandBoxCo

StyleHandler viewStyleHandler = StyleHandlerFactory.get(v);
StyleHandler extraStyleHandler = StyleHandlerFactory.extraGet(v);
StyleHandler parentStyleHandler = StyleHandlerFactory.get(v);
StyleHandler parentStyleHandler = StyleHandlerFactory.parentGet(v);

LayoutStyleHandler parentLayoutAttr = null;
if (parentStyleHandler instanceof LayoutStyleHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ public static Background createOrChange(String param, String val, Object oldOne)
style.setX(0f);
style.xMode = PERCENTAGE;
} else if (item.equals("right")) {
style.setX(100);
style.setX(1.f);
style.xMode = PERCENTAGE;
} else if (item.equals("center")) {
style.setX(50);
style.setX(0.5f);
style.xMode = PERCENTAGE;
} else {
style.xMode = LENGTH;
Expand All @@ -321,10 +321,10 @@ public static Background createOrChange(String param, String val, Object oldOne)
style.setY(0f);
style.yMode = PERCENTAGE;
} else if (item.equals("bottom")) {
style.setY(100);
style.setY(1.f);
style.yMode = PERCENTAGE;
} else if (item.equals("center")) {
style.setY(50);
style.setY(0.5f);
style.yMode = PERCENTAGE;
} else {
style.yMode = LENGTH;
Expand Down
Loading

0 comments on commit d68aa72

Please sign in to comment.