roberthein / TinyConstraints

Nothing but sugar.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

edges(to:) works incorrectly

xinatanil opened this issue · comments

This UITableViewCellSubclass doesn't work properly, for some reason it just stretches the avatarContainer to cell's edges.

class BuggedCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        let guide = contentView.layoutMarginsGuide        
        let avatarContainer = UIView()
        contentView.addSubview(avatarContainer)
        avatarContainer.edges(to: guide, excluding: .trailing)
        avatarContainer.backgroundColor = .red
        avatarContainer.size(CGSize(width: 100, height: 100), priority: UILayoutPriority(999))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

But this subclass does everything correctly

class BugFreeCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        let guide = contentView.layoutMarginsGuide        
        let avatarContainer = UIView()
        contentView.addSubview(avatarContainer)
        avatarContainer.leading(to: guide)
        avatarContainer.top(to: guide)
        avatarContainer.bottom(to: guide)
        avatarContainer.backgroundColor = .red
        avatarContainer.size(CGSize(width: 100, height: 100), priority: UILayoutPriority(999))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

The subclasses should display identical results, but they don't 😫.

As far as I can see in code there is not implementation that excludes leading and trailing.

Check this function implementation:

func edges(to view: Constrainable, excluding excludedEdge: LayoutEdge = .none, insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints {

Adding support for leading and trailing is trivial, but I am not sure if these two should be considered as edges.

Any thoughts on this @roberthein?