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

Expose MASConstraintMaker's view property #61

Closed
erichoracek opened this issue Apr 16, 2014 · 3 comments
Closed

Expose MASConstraintMaker's view property #61

erichoracek opened this issue Apr 16, 2014 · 3 comments

Comments

@erichoracek
Copy link
Contributor

First off, thanks for the amazing library! You've successfully made writing autolayout code a breeze.

It would be helpful to have MASConstraintMaker's view property exposed so that the following code could be written:

[view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(make.view.superview);
}];

This way, constraints could be defined relative to the view's superview, regardless of if the superview is changed down the line in your implementation.

Additionally, this means that copy-pasting layout code when writing it would result in less occurrences of:

[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(view1.superview);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(view1.superview);
}];

Where view2 is constrained to view1's superview, which is an easy to miss but hard to debug error.

@nickynick
Copy link
Contributor

I thought it'd be worth to point out that for a single edge, you can write like this: make.top.equalTo(@10);. This is identical to make.top.equalTo(view.superview).with.offset(10);.

Perhaps it would be nice be able to do the same with edges/sizes, something like this: make.edges.equalTo([NSValue valueWithUIEdgeInsets:UIEdgeInsetsZero]);. Or, much better, this: make.edges.equalTo(UIEdgeInsetsZero);.

I really like how auto-boxing is implemented in Expecta, and I think we could borrow it for Masonry. Just look how beautiful this would be:

make.height.equalTo(20);
make.size.equalTo(CGSizeMake(50, 100));
make.edges.equalTo(UIEdgeInsetsMake(10, 0, 10, 0));

In fact, I'm willing to give it a shot if it's fine with you @cloudkite :)

@erichoracek
Copy link
Contributor Author

@nickynick Seems reasonable as a fix for this issue—it's much more semantic and overall simpler than my suggestion. Especially if it can be done without breaking the API. 👍

@cloudkite
Copy link
Contributor

@eric-horacek those changes are now in the latest cocoapods release. Closing but if it doesn't cover your use case or you still think its worthwhile please reopen, thanks!

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

3 participants