diff --git a/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java b/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java index 359f854fe5114f..e861a859c5b216 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java +++ b/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java @@ -92,8 +92,6 @@ public class ReactPropertyProcessor extends AbstractProcessor { private static final TypeName PROPERTY_MAP_TYPE = ParameterizedTypeName.get(Map.class, String.class, String.class); - private static final TypeName CONCRETE_PROPERTY_MAP_TYPE = - ParameterizedTypeName.get(HashMap.class, String.class, String.class); private final Map mClasses; @@ -186,7 +184,7 @@ public int compare(PropertyInfo a, PropertyInfo b) { return true; } - private boolean isShadowNodeType(TypeName typeName) { + private static boolean isShadowNodeType(TypeName typeName) { return typeName.equals(SHADOW_NODE_IMPL_TYPE); } @@ -280,7 +278,7 @@ private void generateCode(ClassInfo classInfo, List properties) javaFile.writeTo(mFiler); } - private String getClassName(TypeElement type, String packageName) { + private static String getClassName(TypeElement type, String packageName) { int packageLen = packageName.length() + 1; return type.getQualifiedName().toString().substring(packageLen).replace('.', '$'); } @@ -359,24 +357,25 @@ private static CodeBlock generateSetProperty(ClassInfo info, List return builder.build(); } - private static CodeBlock.Builder getPropertyExtractor( + private static void getPropertyExtractor( ClassInfo classInfo, PropertyInfo info, CodeBlock.Builder builder) { TypeName propertyType = info.propertyType; if (propertyType.equals(STRING_TYPE)) { - return builder.add("value instanceof $L ? ($L)value : null", STRING_TYPE, STRING_TYPE); + builder.add("value instanceof $L ? ($L)value : null", STRING_TYPE, STRING_TYPE); + return; } else if (propertyType.equals(READABLE_ARRAY_TYPE)) { - return builder.add( - "value instanceof $L ? ($L)value : null", - READABLE_ARRAY_TYPE, - READABLE_ARRAY_TYPE); // TODO: use real type but needs import + builder.add( + "value instanceof $L ? ($L)value : null", READABLE_ARRAY_TYPE, READABLE_ARRAY_TYPE); + return; // TODO: use real type but needs import } else if (propertyType.equals(READABLE_MAP_TYPE)) { - return builder.add( - "value instanceof $L ? ($L)value : null", READABLE_MAP_TYPE, READABLE_MAP_TYPE); + builder.add("value instanceof $L ? ($L)value : null", READABLE_MAP_TYPE, READABLE_MAP_TYPE); + return; } else if (propertyType.equals(DYNAMIC_TYPE)) { - return builder.add("new $L(value)", DYNAMIC_FROM_OBJECT_TYPE); + builder.add("new $L(value)", DYNAMIC_FROM_OBJECT_TYPE); + return; } else if (propertyType.equals(YOGA_VALUE_TYPE)) { - return builder.add( - "$T.getDimension(value)", com.facebook.react.bridge.DimensionPropConverter.class); + builder.add("$T.getDimension(value)", com.facebook.react.bridge.DimensionPropConverter.class); + return; } if (BOXED_PRIMITIVES.contains(propertyType)) { @@ -384,46 +383,54 @@ private static CodeBlock.Builder getPropertyExtractor( } if (propertyType.equals(TypeName.BOOLEAN)) { - return builder.add( + builder.add( "!(value instanceof Boolean) ? $L : (boolean)value", info.mProperty.defaultBoolean()); + return; } if (propertyType.equals(TypeName.DOUBLE)) { double defaultDouble = info.mProperty.defaultDouble(); if (Double.isNaN(defaultDouble)) { - return builder.add("!(value instanceof Double) ? $T.NaN : (double)value", Double.class); + builder.add("!(value instanceof Double) ? $T.NaN : (double)value", Double.class); + return; } else { - return builder.add("!(value instanceof Double) ? $Lf : (double)value", defaultDouble); + builder.add("!(value instanceof Double) ? $Lf : (double)value", defaultDouble); + return; } } if (propertyType.equals(TypeName.FLOAT)) { float defaultFloat = info.mProperty.defaultFloat(); if (Float.isNaN(defaultFloat)) { - return builder.add( + builder.add( "!(value instanceof Double) ? $T.NaN : ((Double)value).floatValue()", Float.class); + return; } else { - return builder.add( + builder.add( "!(value instanceof Double) ? $Lf : ((Double)value).floatValue()", defaultFloat); + return; } } if ("Color".equals(info.mProperty.customType())) { switch (classInfo.getType()) { case VIEW_MANAGER: - return builder.add( + builder.add( "value == null ? $L : $T.getColor(value, view.getContext(), $L)", info.mProperty.defaultInt(), com.facebook.react.bridge.ColorPropConverter.class, info.mProperty.defaultInt()); + return; case SHADOW_NODE: - return builder.add( + builder.add( "value == null ? $L : $T.getColor(value, node.getThemedContext(), $L)", info.mProperty.defaultInt(), com.facebook.react.bridge.ColorPropConverter.class, info.mProperty.defaultInt()); + return; } } else if (propertyType.equals(TypeName.INT)) { - return builder.add( + builder.add( "!(value instanceof Double) ? $L : ((Double)value).intValue()", info.mProperty.defaultInt()); + return; } throw new IllegalArgumentException(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java index 69c7dbd5dc66bd..0cb48ef591b535 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java @@ -7,6 +7,7 @@ package com.facebook.react.views.switchview; +import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; @@ -50,15 +51,11 @@ public void setChecked(boolean checked) { } @Override + @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void setBackgroundColor(int color) { - // Ensure RippleDrawable is preserved for >=21 - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - setBackground( - new RippleDrawable( - createRippleDrawableColorStateList(color), new ColorDrawable(color), null)); - } else { - super.setBackgroundColor(color); - } + setBackground( + new RippleDrawable( + createRippleDrawableColorStateList(color), new ColorDrawable(color), null)); } void setColor(Drawable drawable, @Nullable Integer color) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/CanvasUtil.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/CanvasUtil.java index e8c5460b127f0f..c8440695c013dc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/CanvasUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/CanvasUtil.java @@ -32,11 +32,7 @@ private CanvasUtil() {} */ @SuppressLint({"SoonBlockedPrivateApi", "PrivateApi"}) public static void enableZ(Canvas canvas, boolean enable) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return; - } - - if (Build.VERSION.SDK_INT >= 29) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (enable) { canvas.enableZ(); } else { @@ -79,11 +75,7 @@ private static void fetchOrderMethods() { mReorderBarrierMethod.setAccessible(true); mInorderBarrierMethod.setAccessible(true); - } catch (IllegalAccessException ignore) { - // Do nothing - } catch (InvocationTargetException ignore) { - // Do nothing - } catch (NoSuchMethodException ignore) { + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignore) { // Do nothing } mOrderMethodsFetched = true;