[YogaKit] Fix layout view with yoga disabled #951

Closed
lucasaraujo wants to merge 3 commits from master into main
lucasaraujo commented 2019-11-14 09:57:20 -08:00 (Migrated from github.com)

Problem

  • YogaKit crash when applying layout to a view whose child subview do not have yoga enabled.
    CALayer position contains NaN: [nan nan].

Solution

  • Check if yoga is enabled in the view when applying layout.

Testing plan

Create a container view with yoga enabled
Add to the container a subview to the view with yoga enabled
Add to the container a subview to the view without yoga enabled
Call applyLayoutPreservingOrigin on the container view.

Code:

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 75)];
container.yoga.isEnabled = YES;

UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.isEnabled = YES;
view.yoga.flexBasis = YGPointValue(0);
view.yoga.flexGrow = 1;
[container addSubview:view];

UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)];
[container addSubview:view2];

[container.yoga applyLayoutPreservingOrigin:YES];

Error:

caught "CALayerInvalidGeometry", "CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x7fdd6055c070; position = CGPoint (25 40); bounds = CGRect (0 0; 30 40); delegate = <UIView: 0x7fdd6055dc40; frame = (10 20; 30 40); layer = <CALayer: 0x7fdd6055c070>>; opaque = YES; allowsGroupOpacity = YES; >"
# Problem - YogaKit crash when applying layout to a view whose child subview do not have yoga enabled. ```CALayer position contains NaN: [nan nan].``` # Solution - Check if yoga is enabled in the view when applying layout. # Testing plan Create a container view with yoga enabled Add to the container a subview to the view with yoga enabled Add to the container a subview to the view without yoga enabled Call ```applyLayoutPreservingOrigin``` on the container view. Code: ```objc UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 75)]; container.yoga.isEnabled = YES; UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.isEnabled = YES; view.yoga.flexBasis = YGPointValue(0); view.yoga.flexGrow = 1; [container addSubview:view]; UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)]; [container addSubview:view2]; [container.yoga applyLayoutPreservingOrigin:YES]; ``` Error: ``` caught "CALayerInvalidGeometry", "CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x7fdd6055c070; position = CGPoint (25 40); bounds = CGRect (0 0; 30 40); delegate = <UIView: 0x7fdd6055dc40; frame = (10 20; 30 40); layer = <CALayer: 0x7fdd6055c070>>; opaque = YES; allowsGroupOpacity = YES; >" ```
wudijimao commented 2021-06-02 21:44:51 -07:00 (Migrated from github.com)

When Can We Merge it?

When Can We Merge it?
NickGerleman commented 2023-06-13 08:01:31 -07:00 (Migrated from github.com)

We are deprecating YogaKit as part of the Yoga 2.0 release. We are still going to release a new revision based on the current state of the repo, but won't be accepting new contributions, since we are going to be removing it from the repo after.

We are deprecating YogaKit as part of the Yoga 2.0 release. We are still going to release a new revision based on the current state of the repo, but won't be accepting new contributions, since we are going to be removing it from the repo after.

Pull request closed

Sign in to join this conversation.
No description provided.