Fix borderRadius incorrect overrides (#44602)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44602

Fix regression caused by D56943825 where radii set to 0 was not being considered. Also preemptively fix a possible bug with RTL due to incorrect overrides.

Changelog:
[Android][Fixed] - Fix borderRadius incorrect overrides

Reviewed By: NickGerleman

Differential Revision: D57473482

fbshipit-source-id: d22a46bdd271d5f254e7d7e54abc55c00a8da8f2
This commit is contained in:
Jorge Cabiedes Acosta
2024-05-20 05:18:50 -07:00
committed by Facebook GitHub Bot
parent 06e37bb194
commit 8d5bbca1eb
2 changed files with 24 additions and 20 deletions
@@ -28,7 +28,7 @@ public class LengthPercentage(
return when (dynamic.getType()) {
ReadableType.Number -> {
val value = dynamic.asDouble()
if (value > 0f) {
if (value >= 0f) {
LengthPercentage(PixelUtil.toPixelFromDIP(value), LengthPercentageType.POINT)
} else {
null
@@ -39,7 +39,7 @@ public class LengthPercentage(
if (s.endsWith("%")) {
try {
val value = s.substring(0, s.length - 1).toFloat()
if (value > 0f) {
if (value >= 0f) {
LengthPercentage(value, LengthPercentageType.PERCENT)
} else {
null
@@ -107,36 +107,40 @@ public data class BorderRadiusStyle(
width: Float,
height: Float,
): ComputedBorderRadius {
val topLeft: LengthPercentage? = startStart ?: topStart ?: topLeft ?: uniform
val topRight: LengthPercentage? = endStart ?: topEnd ?: topRight ?: uniform
val bottomLeft: LengthPercentage? = startEnd ?: bottomStart ?: bottomLeft ?: uniform
val bottomRight: LengthPercentage? = endEnd ?: bottomEnd ?: bottomRight ?: uniform
return when (layoutDirection) {
LayoutDirection.LTR ->
ComputedBorderRadius(
topLeft = topLeft?.resolve(width, height) ?: 0f,
topRight = topRight?.resolve(width, height) ?: 0f,
bottomLeft = bottomLeft?.resolve(width, height) ?: 0f,
bottomRight = bottomRight?.resolve(width, height) ?: 0f,
topLeft =
(startStart ?: topStart ?: topLeft ?: uniform)?.resolve(width, height) ?: 0f,
topRight = (endStart ?: topEnd ?: topRight ?: uniform)?.resolve(width, height) ?: 0f,
bottomLeft =
(startEnd ?: bottomStart ?: bottomLeft ?: uniform)?.resolve(width, height) ?: 0f,
bottomRight =
(endEnd ?: bottomEnd ?: bottomRight ?: uniform)?.resolve(width, height) ?: 0f,
)
LayoutDirection.RTL ->
if (I18nUtil.instance.doLeftAndRightSwapInRTL(context)) {
ComputedBorderRadius(
topLeft = topRight?.resolve(width, height) ?: 0f,
topRight = topLeft?.resolve(width, height) ?: 0f,
bottomLeft = bottomRight?.resolve(width, height) ?: 0f,
bottomRight = bottomLeft?.resolve(width, height) ?: 0f,
topLeft = (endStart ?: topEnd ?: topRight ?: uniform)?.resolve(width, height) ?: 0f,
topRight =
(startStart ?: topStart ?: topLeft ?: uniform)?.resolve(width, height) ?: 0f,
bottomLeft =
(endEnd ?: bottomStart ?: bottomRight ?: uniform)?.resolve(width, height) ?: 0f,
bottomRight =
(startEnd ?: bottomEnd ?: bottomLeft ?: uniform)?.resolve(width, height) ?: 0f,
)
} else {
ComputedBorderRadius(
topLeft = topRight?.resolve(width, height) ?: 0f,
topRight = topLeft?.resolve(width, height) ?: 0f,
bottomLeft = bottomRight?.resolve(width, height) ?: 0f,
bottomRight = bottomLeft?.resolve(width, height) ?: 0f,
topLeft = (endStart ?: topEnd ?: topLeft ?: uniform)?.resolve(width, height) ?: 0f,
topRight =
(startStart ?: topStart ?: topRight ?: uniform)?.resolve(width, height) ?: 0f,
bottomLeft =
(endEnd ?: bottomStart ?: bottomLeft ?: uniform)?.resolve(width, height) ?: 0f,
bottomRight =
(startEnd ?: bottomEnd ?: bottomRight ?: uniform)?.resolve(width, height) ?: 0f,
)
}
else -> throw IllegalArgumentException("Expected resolved layout direction")
else -> throw IllegalArgumentException("Expected?.resolved layout direction")
}
}
}