Skip to content

Commit

Permalink
fix issues with basic FlatList example
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlntn committed Jan 31, 2024
1 parent b5431ee commit 366001c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export default class AnimatedInterpolation<
if (typeof processedColor === 'number') {
outputType = 'color';
return processedColor;
} else if (processedColor.hasOwnProperty('space')) {
} else if (processedColor?.hasOwnProperty('space')) {
const {r, g, b, a} = processedColor;
const reprocessedColor = processColor(
`rgba(${r * 255}, ${g * 255}, ${b * 255}, ${a})`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,29 @@ public void setBackgroundColor(@NonNull T view, int backgroundColor) {

@ReactProp(
name = ViewProps.BACKGROUND_COLOR,
defaultInt = Color.TRANSPARENT,
customType = "Color")
public void setBackgroundColor(@NonNull T view, long backgroundColor) {
FLog.e("RYAN", "long BaseViewManager.setBackgroundColor: " + backgroundColor);
// FLog.e("RYAN", "long BaseViewManager.setBackgroundColor: " + backgroundColor);

// Check if the view class has a setBackgroundColor(long) method
try {
Method setBackgroundColorMethod = view.getClass().getMethod("setBackgroundColor", long.class);
FLog.e("RYAN", "setBackgroundColor(long) method was found in the view class");
// FLog.e("RYAN", "setBackgroundColor(long) method was found in the view class");

// If the method is found, invoke it
setBackgroundColorMethod.invoke(view, backgroundColor);

} catch (NoSuchMethodException e) {
// Log or handle the case where the method doesn't exist
FLog.e("RYAN", "setBackgroundColor(long) method not found in the view class");
// FLog.e("RYAN", "setBackgroundColor(long) method not found in the view class");

// Fallback to the existing code with casting to int
view.setBackgroundColor((int) backgroundColor);

} catch (Exception e) {
// Handle other reflection-related exceptions
FLog.e("RYAN", "Error invoking setBackgroundColor(long): " + e.getMessage());
// FLog.e("RYAN", "Error invoking setBackgroundColor(long): " + e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface BaseViewManagerInterface<T extends View> {
void setElevation(T view, float elevation);

void setShadowColor(T view, int shadowColor);
void setShadowColor(T view, long shadowColor);

void setImportantForAccessibility(T view, @Nullable String importantForAccessibility);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ private static PropSetter createPropSetter(
return new ColorPropSetter(annotation, method, annotation.defaultInt());
}
return new IntPropSetter(annotation, method, annotation.defaultInt());
} else if (propTypeClass == long.class && "Color".equals(annotation.customType())) {
return new ColorPropSetter(annotation, method, annotation.defaultInt());
} else if (propTypeClass == float.class) {
return new FloatPropSetter(annotation, method, annotation.defaultFloat());
} else if (propTypeClass == double.class) {
Expand All @@ -457,12 +459,12 @@ private static PropSetter createPropSetter(
return new BoxedColorPropSetter(annotation, method);
}
return new BoxedIntPropSetter(annotation, method);
} else if (propTypeClass == Long.class && "Color".equals(annotation.customType())) {
return new BoxedColorPropSetter(annotation, method);
} else if (propTypeClass == ReadableArray.class) {
return new ArrayPropSetter(annotation, method);
} else if (propTypeClass == ReadableMap.class) {
return new MapPropSetter(annotation, method);
} else if ((propTypeClass == long.class || propTypeClass == Long.class) && "Color".equals(annotation.customType())) {
return new BoxedColorPropSetter(annotation, method);
} else {
throw new RuntimeException(
"Unrecognized type: "
Expand Down Expand Up @@ -492,6 +494,10 @@ private static void createPropSetters(
props.put(names[i], new IntPropSetter(annotation, method, i, annotation.defaultInt()));
}
}
} else if (propTypeClass == long.class && "Color".equals(annotation.customType())) {
for (int i = 0; i < names.length; i++) {
props.put(names[i], new ColorPropSetter(annotation, method, i, annotation.defaultInt()));
}
} else if (propTypeClass == float.class) {
for (int i = 0; i < names.length; i++) {
props.put(names[i], new FloatPropSetter(annotation, method, i, annotation.defaultFloat()));
Expand All @@ -509,7 +515,7 @@ private static void createPropSetters(
props.put(names[i], new BoxedIntPropSetter(annotation, method, i));
}
}
} else if ((propTypeClass == long.class || propTypeClass == Long.class) && "Color".equals(annotation.customType())) {
} else if (propTypeClass == Long.class && "Color".equals(annotation.customType())) {
for (int i = 0; i < names.length; i++) {
props.put(names[i], new BoxedColorPropSetter(annotation, method, i));
}
Expand Down

0 comments on commit 366001c

Please sign in to comment.