Calling applyLayout(preservingOrigin: true) multiplies margin #1023

Closed
opened 2020-07-26 23:53:58 -07:00 by krzysztofpawski · 5 comments
krzysztofpawski commented 2020-07-26 23:53:58 -07:00 (Migrated from github.com)

Report

Issues and Steps to Reproduce

Use YogaKit as a Pod for iOS Project

  - YogaKit (1.18.1):
    - Yoga (~> 1.14)
class ViewController: UIViewController {

    private var viewTest: UIView?

    override func viewDidLoad() {
        super.viewDidLoad()

        let contentView = UIView()
        contentView.backgroundColor = .lightGray
        contentView.configureLayout { (layout) in
          layout.isEnabled = true
          layout.flexDirection = .row
          layout.width = 320
          layout.height = 80
          layout.marginTop = 40
          layout.marginLeft = 10
        }
        view.addSubview(contentView)

        let child1 = UIView()
        child1.backgroundColor = .red
        child1.configureLayout{ (layout)  in
          layout.isEnabled = true
          layout.width = 80
        }
        contentView.addSubview(child1)
        contentView.yoga.applyLayout(preservingOrigin: true)
        viewTest = contentView
        perform(#selector(layoutSubview), with: nil, afterDelay: 1.0)
    }

    @objc func layoutSubview() {
        viewTest?.yoga.applyLayout(preservingOrigin: true)
        perform(#selector(layoutSubview), with: nil, afterDelay: 1.0)
    }
}

Expected Behavior

Layout stays the same. contentView always has a marginTop=40 and marginLeft=10.

Actual Behavior

Each time yoga.applyLayout(preservingOrigin: true) is called margins are accumulated.
yoga_margin

# Report - [ x] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce Use YogaKit as a Pod for iOS Project ``` - YogaKit (1.18.1): - Yoga (~> 1.14) ``` ``` class ViewController: UIViewController { private var viewTest: UIView? override func viewDidLoad() { super.viewDidLoad() let contentView = UIView() contentView.backgroundColor = .lightGray contentView.configureLayout { (layout) in layout.isEnabled = true layout.flexDirection = .row layout.width = 320 layout.height = 80 layout.marginTop = 40 layout.marginLeft = 10 } view.addSubview(contentView) let child1 = UIView() child1.backgroundColor = .red child1.configureLayout{ (layout) in layout.isEnabled = true layout.width = 80 } contentView.addSubview(child1) contentView.yoga.applyLayout(preservingOrigin: true) viewTest = contentView perform(#selector(layoutSubview), with: nil, afterDelay: 1.0) } @objc func layoutSubview() { viewTest?.yoga.applyLayout(preservingOrigin: true) perform(#selector(layoutSubview), with: nil, afterDelay: 1.0) } } ``` # Expected Behavior Layout stays the same. `contentView` always has a `marginTop=40` and `marginLeft=10`. # Actual Behavior Each time `yoga.applyLayout(preservingOrigin: true)` is called margins are accumulated. ![yoga_margin](https://user-images.githubusercontent.com/6144246/88512116-4bd68880-cfe6-11ea-83a2-626af42586c5.gif)
krzysztofpawski commented 2020-07-27 01:27:25 -07:00 (Migrated from github.com)

No, it looks that I still don't understand how it works...

No, it looks that I still don't understand how it works...
cntrump commented 2020-08-12 22:58:19 -07:00 (Migrated from github.com)

YGLayout.m

const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
YGLayout.m ```objc const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero; ```
cntrump commented 2020-08-12 23:10:51 -07:00 (Migrated from github.com)

You should'nt set margin in Root view.

You should'nt set margin in `Root` view.
cntrump commented 2020-08-12 23:26:47 -07:00 (Migrated from github.com)
I fixed in my PR: https://github.com/facebook/yoga/pull/1026
NickGerleman commented 2023-06-13 08:09:26 -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#1023
No description provided.