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

Add ability to chain different view attributes #56

Merged
merged 2 commits into from May 12, 2014
Merged

Conversation

cloudkite
Copy link
Contributor

Composites are great for defining multiple attributes at once. The following example makes top, left, bottom, right equal to superview.

make.edges.equalTo(superview).insets(padding);

However if only three of the sides are equal to superview then we need to repeat quite a bit of code

make.left.equalTo(superview).insets(padding);
make.right.equalTo(superview).insets(padding);
make.bottom.equalTo(superview).insets(padding);
// top needs to be equal to `otherView`
make.top.equalTo(otherView).insets(padding);

This PR makes it possible to chain view attributes to improve readability

make.left.right.and.bottom.equalTo(superview).insets(padding);
make.top.equalTo(otherView).insets(padding);

TODO

  • Write tests
  • Update readme
  • Update changelog
  • Update podspec

@reejosamuel
Copy link

Chaining is awesome much required, everytime i wanted equal width x height
would be great if you can update the podspec for this change.

@nickynick
Copy link
Contributor

@cloudkite Hey! This thing has been bothering me a bit too, and I just had another idea. What if we had something like this:

make.edges.equalTo(superview).with.insets(UIEdgeInsetsMake(MASNoInset, 0, 0, 0));

MASNoInset would be a predefined constant, much like UITableViewAutomaticDimension or UIViewNoIntrinsicMetric. What do you think? :)

@cloudkite
Copy link
Contributor Author

@reejosamuel Its coming soon, I just need to get the free time to add tests and update readmes etc. @nickynick Thanks for the suggestion, I think that could get confusing as insets is currently used for setting constants on constraints and not for excluding/including constraints.

It also limits the reusability of variables, ie if you need to reuse an existing UIEdgeInsets you would need todo:

UIEdgeInsets padding = UIEdgeInsetsMake(20, 10, 20, 10);
make.edges.equalTo(superview).with.insets(UIEdgeInsetsMake(MASNoInset, padding.left, padding.bottom, padding.right));

As opposed to the syntax proposed in this PR:

UIEdgeInsets padding = UIEdgeInsetsMake(20, 10, 20, 10);
make.left.bottom.right.equalTo(superview).with.insets(padding);

@nickynick
Copy link
Contributor

@cloudkite Yeah, I agree. To be honest, I was not aware you could do this: make.top.equalTo(otherView).insets(padding); :)

cloudkite added a commit that referenced this pull request May 12, 2014
Add ability to chain different view attributes
@cloudkite cloudkite merged commit aa0632f into master May 12, 2014
@cloudkite cloudkite deleted the attribute_chaining branch June 6, 2014 21:46
dan-rodrigues pushed a commit to dan-rodrigues/Masonry that referenced this pull request Oct 18, 2014
Add ability to chain different view attributes
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

Successfully merging this pull request may close these issues.

None yet

3 participants