Skip to content

Commit c9cdc1f

Browse files
authored
Don't create a RippleDrawable when the color is transparent (#2575)
## Description When the `GestureHandlerButton` was disabled immediately after clicking it, the ripple animation would show even if its color was set to transparent. This PR updates the background creation logic not to create the `RippleDrawable` when its color would be transparent, which prevents the issue from happening. It also removes some unnecessary SDK version checks, since RN 0.64 is the last supported version starting with Gesture Handler 2.10.0 ## Test plan Tested on the snippet from #2418 (comment)
1 parent f6cd6df commit c9cdc1f

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
212212
// Therefore it might be used as long as:
213213
// 1. ReactViewManager is not a generic class with a possibility to handle another ViewGroup
214214
// 2. There's no way to force native behavior of ReactViewGroup's superclass's onTouchEvent
215-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && selectable is RippleDrawable) {
215+
if (selectable is RippleDrawable) {
216216
val mask = PaintDrawable(Color.WHITE)
217217
mask.setCornerRadius(borderRadius)
218218
selectable.setDrawableByLayerId(android.R.id.mask, mask)
@@ -239,16 +239,8 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
239239
}
240240

241241
private fun createSelectableDrawable(): Drawable? {
242-
// TODO: remove once support for RN 0.63 is dropped, since 0.64 minSdkVersion is 21
243-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
244-
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, resolveOutValue, true)
245-
@Suppress("Deprecation")
246-
return resources.getDrawable(resolveOutValue.resourceId)
247-
}
248-
249-
// Since Android 13, alpha channel in RippleDrawable is clamped between [128, 255]
250-
// see https://github.com/aosp-mirror/platform_frameworks_base/blob/c1bd0480261460584753508327ca8a0c6fc80758/graphics/java/android/graphics/drawable/RippleDrawable.java#L1012
251-
if (rippleColor == Color.TRANSPARENT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
242+
// don't create ripple drawable at all when it's not supposed to be visible
243+
if (rippleColor == Color.TRANSPARENT) {
252244
return null
253245
}
254246

0 commit comments

Comments
 (0)