Skip to content

Commit dff404d

Browse files
committed
Bring change backgroundColor to buttonBackgroundColor
1 parent 17c84f1 commit dff404d

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ class RNGestureHandlerButtonViewManager :
4444
private val mDelegate: ViewManagerDelegate<ButtonViewGroup>
4545

4646
init {
47-
mDelegate =
48-
RNGestureHandlerButtonManagerDelegate<ButtonViewGroup, RNGestureHandlerButtonViewManager>(
49-
this,
50-
)
47+
mDelegate = RNGestureHandlerButtonManagerDelegate<ButtonViewGroup, RNGestureHandlerButtonViewManager>(this)
5148
}
5249

5350
override fun getName() = REACT_CLASS
@@ -203,7 +200,7 @@ class RNGestureHandlerButtonViewManager :
203200

204201
var exclusive = true
205202

206-
private var backgroundColor = Color.TRANSPARENT
203+
private var buttonBackgroundColor = Color.TRANSPARENT
207204
private var needBackgroundUpdate = false
208205
private var lastEventTime = -1L
209206
private var lastAction = -1
@@ -242,24 +239,13 @@ class RNGestureHandlerButtonViewManager :
242239
}
243240

244241
private fun buildBorderStyle(): PathEffect? = when (borderStyle) {
245-
"dotted" -> DashPathEffect(
246-
floatArrayOf(borderWidth, borderWidth, borderWidth, borderWidth),
247-
0f,
248-
)
249-
"dashed" -> DashPathEffect(
250-
floatArrayOf(
251-
borderWidth * 3,
252-
borderWidth * 3,
253-
borderWidth * 3,
254-
borderWidth * 3,
255-
),
256-
0f,
257-
)
242+
"dotted" -> DashPathEffect(floatArrayOf(borderWidth, borderWidth, borderWidth, borderWidth), 0f)
243+
"dashed" -> DashPathEffect(floatArrayOf(borderWidth * 3, borderWidth * 3, borderWidth * 3, borderWidth * 3), 0f)
258244
else -> null
259245
}
260246

261247
override fun setBackgroundColor(color: Int) = withBackgroundUpdate {
262-
backgroundColor = color
248+
buttonBackgroundColor = color
263249
}
264250

265251
override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) {
@@ -322,10 +308,7 @@ class RNGestureHandlerButtonViewManager :
322308
}
323309

324310
// always true when lastEventTime or lastAction have default value (-1)
325-
if (lastEventTime != eventTime ||
326-
lastAction != action ||
327-
action == MotionEvent.ACTION_CANCEL
328-
) {
311+
if (lastEventTime != eventTime || lastAction != action || action == MotionEvent.ACTION_CANCEL) {
329312
lastEventTime = eventTime
330313
lastAction = action
331314
return super.onTouchEvent(event)
@@ -358,7 +341,7 @@ class RNGestureHandlerButtonViewManager :
358341
}
359342
needBackgroundUpdate = false
360343

361-
if (backgroundColor == Color.TRANSPARENT) {
344+
if (buttonBackgroundColor == Color.TRANSPARENT) {
362345
// reset background
363346
background = null
364347
}
@@ -378,13 +361,13 @@ class RNGestureHandlerButtonViewManager :
378361

379362
if (useDrawableOnForeground && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
380363
foreground = selectable
381-
if (backgroundColor != Color.TRANSPARENT) {
382-
updateBackgroundColor(backgroundColor, borderDrawable, null)
364+
if (buttonBackgroundColor != Color.TRANSPARENT) {
365+
updateBackgroundColor(buttonBackgroundColor, borderDrawable, null)
383366
}
384-
} else if (backgroundColor == Color.TRANSPARENT && rippleColor == null) {
367+
} else if (buttonBackgroundColor == Color.TRANSPARENT && rippleColor == null) {
385368
background = LayerDrawable(arrayOf(selectable, borderDrawable))
386369
} else {
387-
updateBackgroundColor(backgroundColor, borderDrawable, selectable)
370+
updateBackgroundColor(buttonBackgroundColor, borderDrawable, selectable)
388371
}
389372
}
390373

@@ -546,8 +529,7 @@ class RNGestureHandlerButtonViewManager :
546529
}
547530
// button can be pressed alongside other button if both are non-exclusive and it doesn't have
548531
// any pressed children (to prevent pressing the parent when children is pressed).
549-
val canBePressedAlongsideOther =
550-
!exclusive && touchResponder?.exclusive != true && !isChildTouched()
532+
val canBePressedAlongsideOther = !exclusive && touchResponder?.exclusive != true && !isChildTouched()
551533

552534
if (!pressed || touchResponder === this || canBePressedAlongsideOther) {
553535
// we set pressed state only for current responder or any non-exclusive button when responder

0 commit comments

Comments
 (0)