Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create a RippleDrawable when the color is transparent #2575

Merged
merged 2 commits into from
Aug 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
// Therefore it might be used as long as:
// 1. ReactViewManager is not a generic class with a possibility to handle another ViewGroup
// 2. There's no way to force native behavior of ReactViewGroup's superclass's onTouchEvent
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && selectable is RippleDrawable) {
if (selectable is RippleDrawable) {
val mask = PaintDrawable(Color.WHITE)
mask.setCornerRadius(borderRadius)
selectable.setDrawableByLayerId(android.R.id.mask, mask)
Expand All @@ -239,16 +239,8 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
}

private fun createSelectableDrawable(): Drawable? {
// TODO: remove once support for RN 0.63 is dropped, since 0.64 minSdkVersion is 21
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, resolveOutValue, true)
@Suppress("Deprecation")
return resources.getDrawable(resolveOutValue.resourceId)
}

// Since Android 13, alpha channel in RippleDrawable is clamped between [128, 255]
// see https://github.com/aosp-mirror/platform_frameworks_base/blob/c1bd0480261460584753508327ca8a0c6fc80758/graphics/java/android/graphics/drawable/RippleDrawable.java#L1012
if (rippleColor == Color.TRANSPARENT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// don't create ripple drawable at all when it's not supposed to be visible
if (rippleColor == Color.TRANSPARENT) {
return null
}

Expand Down
Loading