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

[Android] Fix border styles for touchable components with transparent background color #3096

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 @@ -286,22 +286,11 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
return false
}

private fun updateBackgroundColor(backgroundColor: Int, selectable: Drawable?) {
private fun updateBackgroundColor(backgroundColor: Int, borderDrawable: Drawable, selectable: Drawable?) {
val colorDrawable = PaintDrawable(backgroundColor)
val borderDrawable = PaintDrawable(Color.TRANSPARENT)

if (hasBorderRadii) {
colorDrawable.setCornerRadii(buildBorderRadii())
borderDrawable.setCornerRadii(buildBorderRadii())
}

if (borderWidth > 0f) {
borderDrawable.paint.apply {
style = Paint.Style.STROKE
strokeWidth = borderWidth
color = borderColor ?: Color.BLACK
pathEffect = buildBorderStyle()
}
}

val layerDrawable = LayerDrawable(if (selectable != null) arrayOf(colorDrawable, selectable, borderDrawable) else arrayOf(colorDrawable, borderDrawable))
Expand All @@ -324,6 +313,7 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
}

val selectable = createSelectableDrawable()
val borderDrawable = createBorderDrawable()

if (hasBorderRadii && selectable is RippleDrawable) {
val mask = PaintDrawable(Color.WHITE)
Expand All @@ -334,13 +324,32 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
if (useDrawableOnForeground && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
foreground = selectable
if (_backgroundColor != Color.TRANSPARENT) {
updateBackgroundColor(_backgroundColor, null)
updateBackgroundColor(_backgroundColor, borderDrawable, null)
}
} else if (_backgroundColor == Color.TRANSPARENT && rippleColor == null) {
background = selectable
background = LayerDrawable(arrayOf(selectable, borderDrawable))
} else {
updateBackgroundColor(_backgroundColor, selectable)
updateBackgroundColor(_backgroundColor, borderDrawable, selectable)
}
}

private fun createBorderDrawable(): Drawable {
val borderDrawable = PaintDrawable(Color.TRANSPARENT)

if (hasBorderRadii) {
borderDrawable.setCornerRadii(buildBorderRadii())
}

if (borderWidth > 0f) {
borderDrawable.paint.apply {
style = Paint.Style.STROKE
strokeWidth = borderWidth
color = borderColor ?: Color.BLACK
pathEffect = buildBorderStyle()
}
}

return borderDrawable
}

private fun createSelectableDrawable(): Drawable? {
Expand Down
Loading