From ce9f5345e3b4141fc771879be0d6d615269a79f8 Mon Sep 17 00:00:00 2001 From: Jorge Cabiedes Acosta Date: Wed, 27 Nov 2024 19:57:55 -0800 Subject: [PATCH] Fix Android ensureNoOverlap function and revise implementation (#47989) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47989 - Fixing Android's ensureNoOverlap algorithm. (For real this time) - Improve verbiage for `ensureNoOverlap` function. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D66514729 fbshipit-source-id: 99908deee2232cc125bb0998ae7acd636a1f7e10 --- .../uimanager/style/BorderRadiusStyle.kt | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt index 3ffda73ff2eed4..017bc22b466c17 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt @@ -178,33 +178,32 @@ public data class BorderRadiusStyle( width: Float, height: Float ): ComputedBorderRadius { - val leftInset = topLeft.horizontal + bottomLeft.horizontal - val topInset = topLeft.vertical + topRight.vertical - val rightInset = topRight.horizontal + bottomRight.horizontal - val bottomInset = bottomLeft.vertical + bottomRight.vertical + val leftEdgeRadii = topLeft.vertical + bottomLeft.vertical + val topEdgeRadii = topLeft.horizontal + topRight.horizontal + val rightEdgeRadii = topRight.vertical + bottomRight.vertical + val bottomEdgeRadii = bottomLeft.horizontal + bottomRight.horizontal - val leftInsetScale = if (leftInset > 0) minOf(1.0f, width / leftInset) else 0f - val topInsetScale = if (topInset > 0) minOf(1.0f, height / topInset) else 0f - val rightInsetScale = if (rightInset > 0) minOf(1.0f, width / rightInset) else 0f - val bottomInsetScale = if (bottomInset > 0) minOf(1.0f, height / bottomInset) else 0f + val leftEdgeRadiiScale = if (leftEdgeRadii > 0) minOf(height / leftEdgeRadii, 1f) else 0f + val topEdgeRadiiScale = if (topEdgeRadii > 0) minOf(width / topEdgeRadii, 1f) else 0f + val rightEdgeRadiiScale = if (rightEdgeRadii > 0) minOf(height / rightEdgeRadii, 1f) else 0f + val bottomEdgeRadiiScale = if (bottomEdgeRadii > 0) minOf(width / bottomEdgeRadii, 1f) else 0f return ComputedBorderRadius( topLeft = CornerRadii( - topLeft.horizontal * minOf(topInsetScale, leftInsetScale), - topLeft.vertical * minOf(topInsetScale, leftInsetScale)), + topLeft.horizontal * minOf(topEdgeRadiiScale, leftEdgeRadiiScale), + topLeft.vertical * minOf(topEdgeRadiiScale, leftEdgeRadiiScale)), topRight = CornerRadii( - topRight.horizontal * minOf(topInsetScale, rightInsetScale), - topRight.vertical * minOf(topInsetScale, rightInsetScale)), + topRight.horizontal * minOf(rightEdgeRadiiScale, topEdgeRadiiScale), + topRight.vertical * minOf(rightEdgeRadiiScale, topEdgeRadiiScale)), bottomLeft = CornerRadii( - bottomLeft.horizontal * minOf(bottomInsetScale, leftInsetScale), - bottomLeft.vertical * minOf(bottomInsetScale, leftInsetScale)), + bottomLeft.horizontal * minOf(bottomEdgeRadiiScale, leftEdgeRadiiScale), + bottomLeft.vertical * minOf(bottomEdgeRadiiScale, leftEdgeRadiiScale)), bottomRight = CornerRadii( - bottomRight.horizontal * minOf(bottomInsetScale, rightInsetScale), - bottomRight.vertical * minOf(bottomInsetScale, rightInsetScale)), - ) + bottomRight.horizontal * minOf(bottomEdgeRadiiScale, rightEdgeRadiiScale), + bottomRight.vertical * minOf(bottomEdgeRadiiScale, rightEdgeRadiiScale))) } }