Skip to content

Commit

Permalink
Merge pull request #234 from OhKanghoon/fix-wrap-reverse-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lucdion authored Oct 15, 2023
2 parents 1f8ad06 + b0c7067 commit 8e082fa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Sources/YogaKit/YGLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ static CGFloat YGRoundPixelValue(CGFloat value) {
return roundf(value * scale) / scale;
}

static CGPoint YGPointReplacingNanWithZero(CGPoint const value) {
CGPoint result = value;

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

static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
NSCAssert(
[NSThread isMainThread],
Expand All @@ -529,22 +541,15 @@ static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
}

YGNodeRef node = yoga.node;
const CGPoint topLeft = {
const CGPoint topLeft = YGPointReplacingNanWithZero({
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
};
});

CGPoint bottomRight = {
const CGPoint bottomRight = YGPointReplacingNanWithZero({
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 Down

0 comments on commit 8e082fa

Please sign in to comment.