9
9
10
10
import android .content .Context ;
11
11
import android .content .res .Resources ;
12
- import android .graphics .Color ;
13
- import android .graphics .ColorSpace ;
14
- import android .os .Build ;
15
12
import android .util .TypedValue ;
16
- import androidx .annotation .ColorLong ;
17
13
import androidx .annotation .Nullable ;
18
14
import androidx .core .content .res .ResourcesCompat ;
19
15
import com .facebook .common .logging .FLog ;
@@ -28,17 +24,13 @@ public class ColorPropConverter {
28
24
private static final String ATTR = "attr" ;
29
25
private static final String ATTR_SEGMENT = "attr/" ;
30
26
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 ) {
36
28
if (value == null ) {
37
29
return null ;
38
30
}
39
31
40
- if (apiSupportWideGamut () && value instanceof Double ) {
41
- return Color . valueOf ((( Double ) value ).intValue () );
32
+ if (value instanceof Double ) {
33
+ return (( Double ) value ).intValue ();
42
34
}
43
35
44
36
if (context == null ) {
@@ -47,22 +39,6 @@ public static Color getColorInstance(Object value, Context context) {
47
39
48
40
if (value instanceof ReadableMap ) {
49
41
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
-
66
42
ReadableArray resourcePaths = map .getArray (JSON_KEY );
67
43
68
44
if (resourcePaths == null ) {
@@ -72,8 +48,8 @@ public static Color getColorInstance(Object value, Context context) {
72
48
73
49
for (int i = 0 ; i < resourcePaths .size (); i ++) {
74
50
Integer result = resolveResourcePath (context , resourcePaths .getString (i ));
75
- if (apiSupportWideGamut () && result != null ) {
76
- return Color . valueOf ( result ) ;
51
+ if (result != null ) {
52
+ return result ;
77
53
}
78
54
}
79
55
@@ -87,17 +63,6 @@ public static Color getColorInstance(Object value, Context context) {
87
63
"ColorValue: the value must be a number or Object." );
88
64
}
89
65
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
-
101
66
public static Integer getColor (Object value , Context context , int defaultInt ) {
102
67
try {
103
68
return getColor (value , context );
@@ -124,9 +89,8 @@ public static Integer resolveResourcePath(Context context, @Nullable String reso
124
89
return resolveThemeAttribute (context , resourcePath );
125
90
}
126
91
} 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
130
94
// found then the exception immediately after the for loop will be thrown.
131
95
}
132
96
return null ;
0 commit comments