justifyContent is not work when minWidth and marginLeft was both set. #664

Closed
opened 2017-11-06 00:51:49 -08:00 by lmxxf · 1 comment
lmxxf commented 2017-11-06 00:51:49 -08:00 (Migrated from github.com)

Report

Issues and Steps to Reproduce

Replaces this with steps to repro your issue.
With following code, the innerView is not aligned in center.

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let root = self.view!
        
        let container = UIView()
        container.layer.borderColor = UIColor.red.cgColor
        container.layer.borderWidth = 1
        container.configureLayout { layout in
            layout.isEnabled = true
            layout.minWidth = YGValue(CGFloat(50))
            layout.marginLeft = YGValue(CGFloat(100)) //comment this line would make the blank box be aligned in the center of the container
            layout.flexDirection = .row
            layout.justifyContent = .center
        }
        
        let innerView = UIView()
        innerView.backgroundColor = .black
        container.addSubview(innerView)
        innerView.configureLayout { layout in
            layout.isEnabled = true
            layout.isIncludedInLayout = true
            layout.width = YGValue(CGFloat(20))
            layout.height = YGValue(CGFloat(20))
        }
        
        root.addSubview(container)
        
        let flexibility = YGDimensionFlexibility(rawValue:3)
        container.yoga.applyLayout(preservingOrigin: false, dimensionFlexibility: flexibility)
    }

Expected Behavior

Describe what you expected would happen.
image

Actual Behavior

Describe what actually happened.
image

Link to Code

If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.
5c617a5947/yoga/Yoga.c (L2236)

It seems marginAxisRow is considered as a part of the container's width which I think is wrong.

When applicable, use this fiddle to post a web repro.

# Report - [x] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce ***Replaces this with steps to repro your issue.*** With following code, the innerView is not aligned in center. ``` override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let root = self.view! let container = UIView() container.layer.borderColor = UIColor.red.cgColor container.layer.borderWidth = 1 container.configureLayout { layout in layout.isEnabled = true layout.minWidth = YGValue(CGFloat(50)) layout.marginLeft = YGValue(CGFloat(100)) //comment this line would make the blank box be aligned in the center of the container layout.flexDirection = .row layout.justifyContent = .center } let innerView = UIView() innerView.backgroundColor = .black container.addSubview(innerView) innerView.configureLayout { layout in layout.isEnabled = true layout.isIncludedInLayout = true layout.width = YGValue(CGFloat(20)) layout.height = YGValue(CGFloat(20)) } root.addSubview(container) let flexibility = YGDimensionFlexibility(rawValue:3) container.yoga.applyLayout(preservingOrigin: false, dimensionFlexibility: flexibility) } ``` # Expected Behavior ***Describe what you expected would happen.*** ![image](https://user-images.githubusercontent.com/743174/32432925-e32c4e20-c29e-11e7-9812-8af1b3092953.png) # Actual Behavior ***Describe what actually happened.*** ![image](https://user-images.githubusercontent.com/743174/32432471-61abe56e-c29d-11e7-85d3-26195e0e042d.png) # Link to Code ***If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.*** https://github.com/facebook/yoga/blob/5c617a59474abdd065fdcce84ff180381a3edb45/yoga/Yoga.c#L2236 It seems marginAxisRow is considered as a part of the container's width which I think is wrong. ***When applicable, use this [fiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) to post a web repro.***
woehrl01 commented 2017-11-06 13:28:28 -08:00 (Migrated from github.com)

Thanks @lmxxf for the hint! I pushed a PR at #665

Thanks @lmxxf for the hint! I pushed a PR at #665
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#664
No description provided.