[YogaKit] crash from property "auto" for YGValue #619

Closed
opened 2017-08-29 20:20:46 -07:00 by huynguyen-n · 5 comments
huynguyen-n commented 2017-08-29 20:20:46 -07:00 (Migrated from github.com)

Report

Issues and Steps to Reproduce

I try to set "auto" for some attribute layout like width or height

final class BasicViewController: UIViewController {
    override func viewDidLoad() {
        let containerSize = self.view.bounds.size

        let root = self.view!
        root.backgroundColor = .white
        root.configureLayout { (layout) in
            layout.isEnabled = true
            layout.width = YGValue(value: 10.0, unit: .auto) // YGValue(containerSize.width)
            layout.height = YGValue(value: 10.0, unit: .auto) //YGValue(containerSize.height)
            layout.alignItems = .center
            layout.justifyContent = .center
        }

        let child1 = UIView()
        child1.backgroundColor = .blue
        child1.configureLayout { (layout) in
            layout.isEnabled = true
            layout.width = 100
            layout.height = 10
            layout.marginBottom = 25
        }
        root.addSubview(child1)

        let child2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
        child2.backgroundColor = .green
        child2.configureLayout { (layout) in
            layout.isEnabled = true
            layout.alignSelf = .flexEnd
        }
        root.addSubview(child2)

        let child3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        child3.backgroundColor = .yellow
        child3.configureLayout { (layout) in
            layout.isEnabled = true
            layout.alignSelf = .flexStart
        }
        root.addSubview(child3)

        root.yoga.applyLayout(preservingOrigin: true)
    }
}

That code I got from YogaKitExample application

Expected Behavior

Can set this attribute like Android.

# Report - [x] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce I try to set "auto" for some attribute layout like width or height ``` final class BasicViewController: UIViewController { override func viewDidLoad() { let containerSize = self.view.bounds.size let root = self.view! root.backgroundColor = .white root.configureLayout { (layout) in layout.isEnabled = true layout.width = YGValue(value: 10.0, unit: .auto) // YGValue(containerSize.width) layout.height = YGValue(value: 10.0, unit: .auto) //YGValue(containerSize.height) layout.alignItems = .center layout.justifyContent = .center } let child1 = UIView() child1.backgroundColor = .blue child1.configureLayout { (layout) in layout.isEnabled = true layout.width = 100 layout.height = 10 layout.marginBottom = 25 } root.addSubview(child1) let child2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) child2.backgroundColor = .green child2.configureLayout { (layout) in layout.isEnabled = true layout.alignSelf = .flexEnd } root.addSubview(child2) let child3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) child3.backgroundColor = .yellow child3.configureLayout { (layout) in layout.isEnabled = true layout.alignSelf = .flexStart } root.addSubview(child3) root.yoga.applyLayout(preservingOrigin: true) } } ``` That code I got from YogaKitExample application # Expected Behavior Can set this attribute like Android.
luuduchieu commented 2017-08-29 20:25:18 -07:00 (Migrated from github.com)

Metoo, someone pls fix this, auto is important value for design

Metoo, someone pls fix this, auto is important value for design
Sleen commented 2017-08-30 18:35:26 -07:00 (Migrated from github.com)

Me too.

Setting the margin to auto will get NANs.

The minimal code to reproduce this issue:

    YGNodeRef root = YGNodeNew();

    YGNodeRef child = YGNodeNew();
    YGNodeStyleSetMarginAuto(child, YGEdgeLeft);

    YGNodeInsertChild(root, child, 0);

    YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

    // print nan, nan
    printf("child size: %f, %f\n",
           YGNodeLayoutGetWidth(child),
           YGNodeLayoutGetHeight(child));

    YGNodeFreeRecursive(root);
Me too. Setting the margin to `auto` will get `NAN`s. The minimal code to reproduce this issue: ``` YGNodeRef root = YGNodeNew(); YGNodeRef child = YGNodeNew(); YGNodeStyleSetMarginAuto(child, YGEdgeLeft); YGNodeInsertChild(root, child, 0); YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); // print nan, nan printf("child size: %f, %f\n", YGNodeLayoutGetWidth(child), YGNodeLayoutGetHeight(child)); YGNodeFreeRecursive(root); ```
denisenkoaj commented 2019-03-28 01:26:16 -07:00 (Migrated from github.com)

Did anybody manage to solve this problem?
Or maybe there is any other way to fit the container size to its content?

Did anybody manage to solve this problem? Or maybe there is any other way to fit the container size to its content?
denisenkoaj commented 2019-03-28 01:39:49 -07:00 (Migrated from github.com)

it seems to work as expected

   coreView?.configureLayout { layout in
            layout.width = YGValue(layout.intrinsicSize.width)
        }
it seems to work as expected ``` coreView?.configureLayout { layout in layout.width = YGValue(layout.intrinsicSize.width) } ```
NickGerleman commented 2023-06-13 08:04:44 -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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#619
No description provided.