Skip to content

Commit

Permalink
Ensure that onBoundsDefined width and height is >= 0
Browse files Browse the repository at this point in the history
Summary:
It's theoretically possible that in onBoundsDefined case we would end up using a negative width/height. It could happen when `layoutResult.width` or `layoutResult.height` is less than the sum of paddings and borders.

This diff ensures that the computed content width and height will always be >= 0.

Reviewed By: pentiumao

Differential Revision: D58867365

fbshipit-source-id: c306cf1027c95e01b01af2c78276d40bea53f499
  • Loading branch information
zielinskimz authored and facebook-github-bot committed Jun 21, 2024
1 parent 50c24c4 commit cd685b4
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,18 @@ internal object LithoYogaLayoutFunction {
// going to save the size without padding and border.
val newContentWidth =
(layoutResult.width -
layoutResult.paddingRight -
layoutResult.paddingLeft -
layoutResult.borderRight -
layoutResult.borderLeft)
layoutResult.paddingRight -
layoutResult.paddingLeft -
layoutResult.borderRight -
layoutResult.borderLeft)
.coerceAtLeast(0)
val newContentHeight =
(layoutResult.height -
layoutResult.paddingTop -
layoutResult.paddingBottom -
layoutResult.borderTop -
layoutResult.borderBottom)
layoutResult.paddingTop -
layoutResult.paddingBottom -
layoutResult.borderTop -
layoutResult.borderBottom)
.coerceAtLeast(0)
if (Component.isMountSpec(component) && component is SpecGeneratedComponent) {

hasLayoutSizeChanged =
Expand Down

0 comments on commit cd685b4

Please sign in to comment.