Skip to content

Commit

Permalink
Merge pull request #211 from iohin/master
Browse files Browse the repository at this point in the history
fixed crash with nan dimensions
  • Loading branch information
lucdion authored Jan 20, 2023
2 parents e9100fc + 551371c commit f6a261c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Sources/YogaKit/YGLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,17 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
};

const CGPoint bottomRight = {
CGPoint bottomRight = {
topLeft.x + YGNodeLayoutGetWidth(node),
topLeft.y + YGNodeLayoutGetHeight(node),
};

if (isnan(bottomRight.x)) {
bottomRight.x = 0;
}
if (isnan(bottomRight.y)) {
bottomRight.y = 0;
}

const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
view.frame = (CGRect) {
Expand All @@ -515,8 +521,8 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
.y = YGRoundPixelValue(topLeft.y + origin.y),
},
.size = {
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y),
.width = MAX(0, YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x)),
.height = MAX(0, YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y)),
},
};

Expand Down

0 comments on commit f6a261c

Please sign in to comment.