Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edges(to:) works incorrectly #78

Open
xinatanil opened this issue May 31, 2019 · 1 comment
Open

edges(to:) works incorrectly #78

xinatanil opened this issue May 31, 2019 · 1 comment

Comments

@xinatanil
Copy link

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 😫.

@jdisho
Copy link

jdisho commented Oct 16, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants