Fix and re-enable "view flattening" optimizations for Marketplace

Reviewed By: achen1

Differential Revision: D6751078

fbshipit-source-id: 32bfb9ac64f183fabbba85755be372016722afc6
This commit is contained in:
David Vacca 2018-01-18 17:41:35 -08:00 committed by Facebook Github Bot
parent 493f3e8da5
commit 877f1cde2e
1 changed files with 20 additions and 16 deletions

View File

@ -67,6 +67,10 @@ public class ViewProps {
public static final String START = "start"; public static final String START = "start";
public static final String END = "end"; public static final String END = "end";
public static final String AUTO = "auto";
public static final String NONE = "none";
public static final String BOX_NONE = "box-none";
public static final String MIN_WIDTH = "minWidth"; public static final String MIN_WIDTH = "minWidth";
public static final String MAX_WIDTH = "maxWidth"; public static final String MAX_WIDTH = "maxWidth";
public static final String MIN_HEIGHT = "minHeight"; public static final String MIN_HEIGHT = "minHeight";
@ -124,6 +128,7 @@ public class ViewProps {
public static final String BORDER_BOTTOM_END_RADIUS = "borderBottomEndRadius"; public static final String BORDER_BOTTOM_END_RADIUS = "borderBottomEndRadius";
public static final String BORDER_START_COLOR = "borderStartColor"; public static final String BORDER_START_COLOR = "borderStartColor";
public static final String BORDER_END_COLOR = "borderEndColor"; public static final String BORDER_END_COLOR = "borderEndColor";
public static final String ON_LAYOUT = "onLayout";
public static final int[] BORDER_SPACING_TYPES = { public static final int[] BORDER_SPACING_TYPES = {
Spacing.ALL, Spacing.ALL,
@ -205,7 +210,6 @@ public class ViewProps {
PADDING_START, PADDING_START,
PADDING_END)); PADDING_END));
public static boolean sIsOptimizationsEnabled; public static boolean sIsOptimizationsEnabled;
public static boolean isLayoutOnly(ReadableMap map, String prop) { public static boolean isLayoutOnly(ReadableMap map, String prop) {
@ -213,25 +217,26 @@ public class ViewProps {
return true; return true;
} else if (POINTER_EVENTS.equals(prop)) { } else if (POINTER_EVENTS.equals(prop)) {
String value = map.getString(prop); String value = map.getString(prop);
return "auto".equals(value) || "box-none".equals(value); return AUTO.equals(value) || BOX_NONE.equals(value);
} }
if (sIsOptimizationsEnabled) { if (sIsOptimizationsEnabled) {
switch (prop) { switch (prop) {
case OPACITY: case OPACITY:
return map.getDouble(OPACITY) == 1d; // Ignore if explicitly set to default opacity. // null opacity behaves like opacity = 1
case BACKGROUND_COLOR: // Ignore if explicitly set to default opacity.
return map.getInt(BACKGROUND_COLOR) == Color.TRANSPARENT; return map.isNull(OPACITY) || map.getDouble(OPACITY) == 1d;
case BORDER_RADIUS: // Without a background color or border width set, a border won't show. case BORDER_RADIUS: // Without a background color or border width set, a border won't show.
if (map.hasKey(BACKGROUND_COLOR) && map.getInt(BACKGROUND_COLOR) != Color.TRANSPARENT) { if (map.hasKey(BACKGROUND_COLOR) && map.getInt(BACKGROUND_COLOR) != Color.TRANSPARENT) {
return false; return false;
} }
if (map.hasKey(BORDER_WIDTH) && map.getDouble(BORDER_WIDTH) != 0d) { if (map.hasKey(BORDER_WIDTH)
&& !map.isNull(BORDER_WIDTH)
&& map.getDouble(BORDER_WIDTH) != 0d) {
return false; return false;
} }
return true; return true;
case BORDER_COLOR:
return map.getInt(BORDER_COLOR) == Color.TRANSPARENT;
case BORDER_LEFT_COLOR: case BORDER_LEFT_COLOR:
return map.getInt(BORDER_LEFT_COLOR) == Color.TRANSPARENT; return map.getInt(BORDER_LEFT_COLOR) == Color.TRANSPARENT;
case BORDER_RIGHT_COLOR: case BORDER_RIGHT_COLOR:
@ -241,24 +246,23 @@ public class ViewProps {
case BORDER_BOTTOM_COLOR: case BORDER_BOTTOM_COLOR:
return map.getInt(BORDER_BOTTOM_COLOR) == Color.TRANSPARENT; return map.getInt(BORDER_BOTTOM_COLOR) == Color.TRANSPARENT;
case BORDER_WIDTH: case BORDER_WIDTH:
return map.getDouble(BORDER_WIDTH) == 0d; return map.isNull(BORDER_WIDTH) || map.getDouble(BORDER_WIDTH) == 0d;
case BORDER_LEFT_WIDTH: case BORDER_LEFT_WIDTH:
return map.getDouble(BORDER_LEFT_WIDTH) == 0d; return map.isNull(BORDER_LEFT_WIDTH) || map.getDouble(BORDER_LEFT_WIDTH) == 0d;
case BORDER_TOP_WIDTH: case BORDER_TOP_WIDTH:
return map.getDouble(BORDER_TOP_WIDTH) == 0d; return map.isNull(BORDER_TOP_WIDTH) || map.getDouble(BORDER_TOP_WIDTH) == 0d;
case BORDER_RIGHT_WIDTH: case BORDER_RIGHT_WIDTH:
return map.getDouble(BORDER_RIGHT_WIDTH) == 0d; return map.isNull(BORDER_RIGHT_WIDTH) || map.getDouble(BORDER_RIGHT_WIDTH) == 0d;
case BORDER_BOTTOM_WIDTH: case BORDER_BOTTOM_WIDTH:
return map.getDouble(BORDER_BOTTOM_WIDTH) == 0d; return map.isNull(BORDER_BOTTOM_WIDTH) || map.getDouble(BORDER_BOTTOM_WIDTH) == 0d;
case "onLayout": case ON_LAYOUT:
return true; return true;
case "overflow": // We do nothing with this right now. case OVERFLOW: // We do nothing with this right now.
return true; return true;
default: default:
return false; return false;
} }
} }
return false; return false;
} }
} }