Skip to content

Commit

Permalink
Remove code only used by Android API level < 21
Browse files Browse the repository at this point in the history
Summary:
Min Android API level is 21, this diff is removing code for Android API level < 21

changelog: [RN][Android] removing code for Android API level < 21

Reviewed By: cortinico, RSNara

Differential Revision: D43544497

fbshipit-source-id: 1ece1143a37a038826361b55ff08a8160f03108d
  • Loading branch information
mdvacca authored and facebook-github-bot committed Mar 1, 2023
1 parent cbe934b commit 22ba1e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassName, ClassInfo> mClasses;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -280,7 +278,7 @@ private void generateCode(ClassInfo classInfo, List<PropertyInfo> 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('.', '$');
}
Expand Down Expand Up @@ -359,71 +357,80 @@ private static CodeBlock generateSetProperty(ClassInfo info, List<PropertyInfo>
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)) {
propertyType = propertyType.unbox();
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 22ba1e4

Please sign in to comment.