Skip to content

Commit 05f0861

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Back out "Update ColorPropConverterto support color function values" (facebook#44225)
Summary: Pull Request resolved: facebook#44225 Back out [facebook#43031](facebook#43031) as it makes some internal test fails. ## Changelog: [Android][Fixed] - Revert facebook#43031 Reviewed By: arushikesarwani94 Differential Revision: D56489260 fbshipit-source-id: bd843e6eb60fce0a1d5d8da9f3c5d2a36473ecfb
1 parent 41f525c commit 05f0861

File tree

2 files changed

+7
-44
lines changed

2 files changed

+7
-44
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ public class com/facebook/react/bridge/ColorPropConverter {
649649
public fun <init> ()V
650650
public static fun getColor (Ljava/lang/Object;Landroid/content/Context;)Ljava/lang/Integer;
651651
public static fun getColor (Ljava/lang/Object;Landroid/content/Context;I)Ljava/lang/Integer;
652-
public static fun getColorInstance (Ljava/lang/Object;Landroid/content/Context;)Landroid/graphics/Color;
653652
public static fun resolveResourcePath (Landroid/content/Context;Ljava/lang/String;)Ljava/lang/Integer;
654653
}
655654

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ColorPropConverter.java

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99

1010
import android.content.Context;
1111
import android.content.res.Resources;
12-
import android.graphics.Color;
13-
import android.graphics.ColorSpace;
14-
import android.os.Build;
1512
import android.util.TypedValue;
16-
import androidx.annotation.ColorLong;
1713
import androidx.annotation.Nullable;
1814
import androidx.core.content.res.ResourcesCompat;
1915
import com.facebook.common.logging.FLog;
@@ -28,17 +24,13 @@ public class ColorPropConverter {
2824
private static final String ATTR = "attr";
2925
private static final String ATTR_SEGMENT = "attr/";
3026

31-
private static Boolean apiSupportWideGamut() {
32-
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
33-
}
34-
35-
public static Color getColorInstance(Object value, Context context) {
27+
public static Integer getColor(Object value, Context context) {
3628
if (value == null) {
3729
return null;
3830
}
3931

40-
if (apiSupportWideGamut() && value instanceof Double) {
41-
return Color.valueOf(((Double) value).intValue());
32+
if (value instanceof Double) {
33+
return ((Double) value).intValue();
4234
}
4335

4436
if (context == null) {
@@ -47,22 +39,6 @@ public static Color getColorInstance(Object value, Context context) {
4739

4840
if (value instanceof ReadableMap) {
4941
ReadableMap map = (ReadableMap) value;
50-
51-
// handle color(space r g b a) value
52-
if (apiSupportWideGamut() && map.hasKey("space")) {
53-
String rawColorSpace = map.getString("space");
54-
boolean isDisplayP3 = rawColorSpace.equals("display-p3");
55-
ColorSpace space =
56-
ColorSpace.get(isDisplayP3 ? ColorSpace.Named.DISPLAY_P3 : ColorSpace.Named.SRGB);
57-
float r = (float) map.getDouble("r");
58-
float g = (float) map.getDouble("g");
59-
float b = (float) map.getDouble("b");
60-
float a = (float) map.getDouble("a");
61-
62-
@ColorLong long color = Color.pack(r, g, b, a, space);
63-
return Color.valueOf(color);
64-
}
65-
6642
ReadableArray resourcePaths = map.getArray(JSON_KEY);
6743

6844
if (resourcePaths == null) {
@@ -72,8 +48,8 @@ public static Color getColorInstance(Object value, Context context) {
7248

7349
for (int i = 0; i < resourcePaths.size(); i++) {
7450
Integer result = resolveResourcePath(context, resourcePaths.getString(i));
75-
if (apiSupportWideGamut() && result != null) {
76-
return Color.valueOf(result);
51+
if (result != null) {
52+
return result;
7753
}
7854
}
7955

@@ -87,17 +63,6 @@ public static Color getColorInstance(Object value, Context context) {
8763
"ColorValue: the value must be a number or Object.");
8864
}
8965

90-
public static Integer getColor(Object value, Context context) {
91-
Color color = getColorInstance(value, context);
92-
if (color == null) {
93-
return null;
94-
}
95-
if (apiSupportWideGamut()) {
96-
return color.toArgb();
97-
}
98-
return null;
99-
}
100-
10166
public static Integer getColor(Object value, Context context, int defaultInt) {
10267
try {
10368
return getColor(value, context);
@@ -124,9 +89,8 @@ public static Integer resolveResourcePath(Context context, @Nullable String reso
12489
return resolveThemeAttribute(context, resourcePath);
12590
}
12691
} catch (Resources.NotFoundException exception) {
127-
// The resource could not be found so do nothing to allow the for loop to
128-
// continue and
129-
// try the next fallback resource in the array. If none of the fallbacks are
92+
// The resource could not be found so do nothing to allow the for loop to continue and
93+
// try the next fallback resource in the array. If none of the fallbacks are
13094
// found then the exception immediately after the for loop will be thrown.
13195
}
13296
return null;

0 commit comments

Comments
 (0)