Export latest Android changes

This commit is contained in:
Martin Konicek
2015-09-17 14:33:23 +01:00
parent 3b4845f93c
commit 27ab039b6a
32 changed files with 685 additions and 792 deletions

View File

@@ -23,7 +23,6 @@ import com.facebook.react.bridge.ReadableMap;
*/
public class BaseViewPropertyApplicator {
private static final String PROP_BACKGROUND_COLOR = ViewProps.BACKGROUND_COLOR;
private static final String PROP_DECOMPOSED_MATRIX = "decomposedMatrix";
private static final String PROP_DECOMPOSED_MATRIX_ROTATE = "rotate";
private static final String PROP_DECOMPOSED_MATRIX_SCALE_X = "scaleX";
@@ -55,7 +54,7 @@ public class BaseViewPropertyApplicator {
props.put(PROP_ACCESSIBILITY_LABEL, UIProp.Type.STRING);
props.put(PROP_ACCESSIBILITY_COMPONENT_TYPE, UIProp.Type.STRING);
props.put(PROP_ACCESSIBILITY_LIVE_REGION, UIProp.Type.STRING);
props.put(PROP_BACKGROUND_COLOR, UIProp.Type.STRING);
props.put(ViewProps.BACKGROUND_COLOR, UIProp.Type.STRING);
props.put(PROP_IMPORTANT_FOR_ACCESSIBILITY, UIProp.Type.STRING);
props.put(PROP_OPACITY, UIProp.Type.NUMBER);
props.put(PROP_ROTATION, UIProp.Type.NUMBER);
@@ -73,13 +72,9 @@ public class BaseViewPropertyApplicator {
}
public static void applyCommonViewProperties(View view, CatalystStylesDiffMap props) {
if (props.hasKey(PROP_BACKGROUND_COLOR)) {
String backgroundString = props.getString(PROP_BACKGROUND_COLOR);
if (backgroundString == null) {
view.setBackgroundColor(Color.TRANSPARENT);
} else {
view.setBackgroundColor(CSSColorUtil.getColor(backgroundString));
}
if (props.hasKey(ViewProps.BACKGROUND_COLOR)) {
final int backgroundColor = props.getColorInt(ViewProps.BACKGROUND_COLOR, Color.TRANSPARENT);
view.setBackgroundColor(backgroundColor);
}
if (props.hasKey(PROP_DECOMPOSED_MATRIX)) {
ReadableMap decomposedMatrix = props.getMap(PROP_DECOMPOSED_MATRIX);

View File

@@ -67,6 +67,17 @@ public class CatalystStylesDiffMap {
return mBackingMap.isNull(name) ? restoreNullToDefaultValue : (int) mBackingMap.getDouble(name);
}
// Colors have values between 0x00000000 and 0xFFFFFFFF, which fits in an integer, but is sent as
// a double over the bridge. Because color values can be higher than Integer.MAX_VALUE, it is not
// correct to convert doubles to int directly, since they can be truncated to Integer.MAX_VALUE
// instead of being converted to negative values. Converting from double to long maintains the
// initial value, and is then correctly converted to int. This is the expected behavior according
// to the java spec, see http://stackoverflow.com/questions/10641559 for more.
public int getColorInt(String name, int restoreNullToDefaultValue) {
return mBackingMap.isNull(name) ? restoreNullToDefaultValue :
(int) (long) mBackingMap.getDouble(name);
}
@Nullable
public String getString(String name) {
return mBackingMap.getString(name);

View File

@@ -36,7 +36,8 @@ public @interface UIProp {
NUMBER("number"),
STRING("String"),
MAP("Map"),
ARRAY("Array");
ARRAY("Array"),
COLOR("Color");
private final String mType;