99
1010import android .content .Context ;
1111import android .content .res .Resources ;
12- import android .graphics .Color ;
13- import android .graphics .ColorSpace ;
14- import android .os .Build ;
1512import android .util .TypedValue ;
16- import androidx .annotation .ColorLong ;
1713import androidx .annotation .Nullable ;
1814import androidx .core .content .res .ResourcesCompat ;
1915import 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