Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Libraries/Components/Pressable/useAndroidRippleForView.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type NativeBackgroundProp = $ReadOnly<{|
color: ?number,
borderless: boolean,
rippleRadius: ?number,
rippleCornerRadius: ?number,
|}>;

export type RippleConfig = {|
color?: ColorValue,
borderless?: boolean,
radius?: number,
cornerRadius?: number,
foreground?: boolean,
|};

Expand All @@ -45,7 +47,8 @@ export default function useAndroidRippleForView(
| $ReadOnly<{|nativeBackgroundAndroid: NativeBackgroundProp|}>
| $ReadOnly<{|nativeForegroundAndroid: NativeBackgroundProp|}>,
|}> {
const {color, borderless, radius, foreground} = rippleConfig ?? {};
const {color, borderless, radius, cornerRadius, foreground} =
rippleConfig ?? {};

return useMemo(() => {
if (
Expand All @@ -64,6 +67,7 @@ export default function useAndroidRippleForView(
color: processedColor,
borderless: borderless === true,
rippleRadius: radius,
rippleCornerRadius: cornerRadius,
};

return {
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ type AndroidDrawableRipple = $ReadOnly<{|
color?: ?number,
borderless?: ?boolean,
rippleRadius?: ?number,
rippleCornerRadius?: ?number,
|}>;

type AndroidDrawable = AndroidDrawableThemeAttr | AndroidDrawableRipple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.os.Build;
import android.util.TypedValue;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -106,11 +108,16 @@ private static int getColor(Context context, ReadableMap drawableDescriptionDict
}

private static @Nullable Drawable getMask(ReadableMap drawableDescriptionDict) {
if (!drawableDescriptionDict.hasKey("borderless")
|| drawableDescriptionDict.isNull("borderless")
|| !drawableDescriptionDict.getBoolean("borderless")) {
return new ColorDrawable(Color.WHITE);
if (drawableDescriptionDict.hasKey("borderless") && drawableDescriptionDict.getBoolean("borderless")) {
// Borderless ripples don't have masks.
return null;
}
return null;

if (drawableDescriptionDict.hasKey("rippleCornerRadius")) {
float rippleRadius = PixelUtil.toPixelFromDIP(drawableDescriptionDict.getDouble("rippleCornerRadius"));
return new ShapeDrawable(new RoundRectShape(new float[] {rippleRadius, rippleRadius, rippleRadius, rippleRadius, rippleRadius, rippleRadius, rippleRadius, rippleRadius}, null, null));
}

return new ColorDrawable(Color.WHITE);
}
}