Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0cf0f46

Browse files
committedJun 30, 2022
Ripple radius now applies to corner radius instead of circular radius
1 parent a3f807f commit 0cf0f46

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/views/view/ReactDrawableHelper.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -14,6 +14,8 @@
1414
import android.graphics.drawable.ColorDrawable;
1515
import android.graphics.drawable.Drawable;
1616
import android.graphics.drawable.RippleDrawable;
17+
import android.graphics.drawable.ShapeDrawable;
18+
import android.graphics.drawable.shapes.RoundRectShape;
1719
import android.os.Build;
1820
import android.util.TypedValue;
1921
import androidx.annotation.Nullable;
@@ -23,6 +25,8 @@
2325
import com.facebook.react.uimanager.PixelUtil;
2426
import com.facebook.react.uimanager.ViewProps;
2527

28+
import java.util.Collections;
29+
2630
/**
2731
* Utility class that helps with converting android drawable description used in JS to an actual
2832
* instance of {@link Drawable}.
@@ -45,8 +49,7 @@ public static Drawable createDrawableFromJSDescription(
4549
Drawable drawable = getDefaultThemeDrawable(context);
4650
return setRadius(drawableDescriptionDict, drawable);
4751
} else if ("RippleAndroid".equals(type)) {
48-
RippleDrawable rd = getRippleDrawable(context, drawableDescriptionDict);
49-
return setRadius(drawableDescriptionDict, rd);
52+
return getRippleDrawable(context, drawableDescriptionDict);
5053
} else {
5154
throw new JSApplicationIllegalArgumentException("Invalid type for android drawable: " + type);
5255
}
@@ -106,11 +109,16 @@ private static int getColor(Context context, ReadableMap drawableDescriptionDict
106109
}
107110

108111
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));
113120
}
114-
return null;
121+
122+
return new ColorDrawable(Color.WHITE);
115123
}
116124
}

0 commit comments

Comments
 (0)
Please sign in to comment.