1
1
/*
2
- * Copyright (c) Facebook , Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms , Inc. and affiliates.
3
3
*
4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
14
14
import android .graphics .drawable .ColorDrawable ;
15
15
import android .graphics .drawable .Drawable ;
16
16
import android .graphics .drawable .RippleDrawable ;
17
+ import android .graphics .drawable .ShapeDrawable ;
18
+ import android .graphics .drawable .shapes .RoundRectShape ;
17
19
import android .os .Build ;
18
20
import android .util .TypedValue ;
19
21
import androidx .annotation .Nullable ;
23
25
import com .facebook .react .uimanager .PixelUtil ;
24
26
import com .facebook .react .uimanager .ViewProps ;
25
27
28
+ import java .util .Collections ;
29
+
26
30
/**
27
31
* Utility class that helps with converting android drawable description used in JS to an actual
28
32
* instance of {@link Drawable}.
@@ -45,8 +49,7 @@ public static Drawable createDrawableFromJSDescription(
45
49
Drawable drawable = getDefaultThemeDrawable (context );
46
50
return setRadius (drawableDescriptionDict , drawable );
47
51
} else if ("RippleAndroid" .equals (type )) {
48
- RippleDrawable rd = getRippleDrawable (context , drawableDescriptionDict );
49
- return setRadius (drawableDescriptionDict , rd );
52
+ return getRippleDrawable (context , drawableDescriptionDict );
50
53
} else {
51
54
throw new JSApplicationIllegalArgumentException ("Invalid type for android drawable: " + type );
52
55
}
@@ -106,11 +109,16 @@ private static int getColor(Context context, ReadableMap drawableDescriptionDict
106
109
}
107
110
108
111
private static @ Nullable Drawable getMask (ReadableMap drawableDescriptionDict ) {
109
- if (!drawableDescriptionDict .hasKey ("borderless" )
110
- || drawableDescriptionDict .isNull ("borderless" )
111
- || !drawableDescriptionDict .getBoolean ("borderless" )) {
112
- return new ColorDrawable (Color .WHITE );
112
+ if (drawableDescriptionDict .hasKey ("borderless" ) && drawableDescriptionDict .getBoolean ("borderless" )) {
113
+ // Borderless ripples don't have masks.
114
+ return null ;
115
+ }
116
+
117
+ if (drawableDescriptionDict .hasKey ("rippleRadius" )) {
118
+ float rippleRadius = PixelUtil .toPixelFromDIP (drawableDescriptionDict .getDouble ("rippleRadius" ));
119
+ return new ShapeDrawable (new RoundRectShape (new float [] {rippleRadius , rippleRadius , rippleRadius , rippleRadius , rippleRadius , rippleRadius , rippleRadius , rippleRadius }, null , null ));
113
120
}
114
- return null ;
121
+
122
+ return new ColorDrawable (Color .WHITE );
115
123
}
116
124
}
0 commit comments