Skip to content

Commit 0877a36

Browse files
committed
Fixing resetting image tintColor on Android
1 parent b84ae38 commit 0877a36

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ protected Object getValueOrDefault(Object value, Context context) {
214214
}
215215
}
216216

217+
private static class NullableColorPropSetter extends PropSetter {
218+
219+
private final int mDefaultValue;
220+
221+
public NullableColorPropSetter(ReactProp prop, Method setter) {
222+
this(prop, setter, 0);
223+
}
224+
225+
public NullableColorPropSetter(ReactProp prop, Method setter, int defaultValue) {
226+
super(prop, "mixed", setter);
227+
mDefaultValue = defaultValue;
228+
}
229+
230+
@Override
231+
protected Object getValueOrDefault(Object value, Context context) {
232+
if (value == null) {
233+
return null;
234+
}
235+
236+
return ColorPropConverter.getColor(value, context);
237+
}
238+
}
239+
217240
private static class BooleanPropSetter extends PropSetter {
218241

219242
private final boolean mDefaultValue;
@@ -407,6 +430,9 @@ private static PropSetter createPropSetter(
407430
if ("Color".equals(annotation.customType())) {
408431
return new ColorPropSetter(annotation, method, annotation.defaultInt());
409432
}
433+
if ("NullableColor".equals(annotation.customType())) {
434+
return new NullableColorPropSetter(annotation, method, annotation.defaultInt());
435+
}
410436
return new IntPropSetter(annotation, method, annotation.defaultInt());
411437
} else if (propTypeClass == float.class) {
412438
return new FloatPropSetter(annotation, method, annotation.defaultFloat());
@@ -420,6 +446,9 @@ private static PropSetter createPropSetter(
420446
if ("Color".equals(annotation.customType())) {
421447
return new ColorPropSetter(annotation, method);
422448
}
449+
if ("NullableColor".equals(annotation.customType())) {
450+
return new NullableColorPropSetter(annotation, method, annotation.defaultInt());
451+
}
423452
return new BoxedIntPropSetter(annotation, method);
424453
} else if (propTypeClass == ReadableArray.class) {
425454
return new ArrayPropSetter(annotation, method);

ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void setLoadingIndicatorSource(ReactImageView view, @Nullable String sour
145145
view.setLoadingIndicatorSource(source);
146146
}
147147

148-
@ReactProp(name = "borderColor", customType = "Color")
148+
@ReactProp(name = "borderColor", customType = "NullableColor")
149149
public void setBorderColor(ReactImageView view, @Nullable Integer borderColor) {
150150
if (borderColor == null) {
151151
view.setBorderColor(Color.TRANSPARENT);
@@ -154,7 +154,7 @@ public void setBorderColor(ReactImageView view, @Nullable Integer borderColor) {
154154
}
155155
}
156156

157-
@ReactProp(name = "overlayColor", customType = "Color")
157+
@ReactProp(name = "overlayColor", customType = "NullableColor")
158158
public void setOverlayColor(ReactImageView view, @Nullable Integer overlayColor) {
159159
if (overlayColor == null) {
160160
view.setOverlayColor(Color.TRANSPARENT);
@@ -209,7 +209,7 @@ public void setResizeMethod(ReactImageView view, @Nullable String resizeMethod)
209209
}
210210
}
211211

212-
@ReactProp(name = "tintColor", customType = "Color")
212+
@ReactProp(name = "tintColor", customType = "NullableColor")
213213
public void setTintColor(ReactImageView view, @Nullable Integer tintColor) {
214214
if (tintColor == null) {
215215
view.clearColorFilter();

0 commit comments

Comments
 (0)