Skip to content

Commit 8e082fa

Browse files
authored
Merge pull request #234 from OhKanghoon/fix-wrap-reverse-crash
2 parents 1f8ad06 + b0c7067 commit 8e082fa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Sources/YogaKit/YGLayout.mm

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,18 @@ static CGFloat YGRoundPixelValue(CGFloat value) {
517517
return roundf(value * scale) / scale;
518518
}
519519

520+
static CGPoint YGPointReplacingNanWithZero(CGPoint const value) {
521+
CGPoint result = value;
522+
523+
if (isnan(result.x)) {
524+
result.x = 0;
525+
}
526+
if (isnan(result.y)) {
527+
result.y = 0;
528+
}
529+
return result;
530+
}
531+
520532
static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
521533
NSCAssert(
522534
[NSThread isMainThread],
@@ -529,22 +541,15 @@ static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
529541
}
530542

531543
YGNodeRef node = yoga.node;
532-
const CGPoint topLeft = {
544+
const CGPoint topLeft = YGPointReplacingNanWithZero({
533545
YGNodeLayoutGetLeft(node),
534546
YGNodeLayoutGetTop(node),
535-
};
547+
});
536548

537-
CGPoint bottomRight = {
549+
const CGPoint bottomRight = YGPointReplacingNanWithZero({
538550
topLeft.x + YGNodeLayoutGetWidth(node),
539551
topLeft.y + YGNodeLayoutGetHeight(node),
540-
};
541-
542-
if (isnan(bottomRight.x)) {
543-
bottomRight.x = 0;
544-
}
545-
if (isnan(bottomRight.y)) {
546-
bottomRight.y = 0;
547-
}
552+
});
548553

549554
const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
550555
view.frame = (CGRect){

0 commit comments

Comments
 (0)