Skip to content

Commit

Permalink
Fix Android ensureNoOverlap function and revise implementation (#47989)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
jorge-cab authored and facebook-github-bot committed Nov 28, 2024
1 parent 5da7089 commit ce9f534
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

0 comments on commit ce9f534

Please sign in to comment.