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 Hugging and CompressionResistance Please #344

Open
iStarEternal opened this issue May 18, 2016 · 9 comments
Open

Add Hugging and CompressionResistance Please #344

iStarEternal opened this issue May 18, 2016 · 9 comments

Comments

@iStarEternal
Copy link

iStarEternal commented May 18, 2016

I want to add hugging constraint to a view now, but it is not elegant code to write so

[self.footTitleSignBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.footView);
    make.centerY.equalTo(self.footView.mas_centerY).offset(0);
}];
[self.footTitleSignBackgroundView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[self.footTitleSignBackgroundView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

I think you should add this syntax into Masonry

make.horizontal.huggingRequired()
make.horizontal.huggingHigh()
make.horizontal.huggingFittingSizeLevel()
make.horizontal.huggingLow()
make.vertical...
make.horizontal.compressionResistance...
make.vertical.compressionResistance...
@robertjpayne
Copy link
Member

Happy to accept a well proposed PR for this but otherwise as per the readme we're currently focusing any feature development exclusively into SnapKit.

@iStarEternal
Copy link
Author

Is really a terrible news, I hope you can combined with the above in SnapKit

@robertjpayne
Copy link
Member

@iStarEternal it's not really terrible news, it's pretty much just me maintaining the two repositories now and I just don't have enough time. Neither project is financially sponsored so I can't just take time off to work on both.

@iStarEternal
Copy link
Author

Sorry for my grammar, my English is not very good. Hope that you can understand what I had written.
Thanks for your SnapKit & Masonry. It makes the code is simple, easy to read and elegant. This popularity in China. You are a great Programmer. ;-)

@iStarEternal
Copy link
Author

iStarEternal commented Jul 1, 2016

@robertjpayne
Do you remember me?
I fix my issues, It's non destructive.
You can use it like so:
[button makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(100);
make.top.equalTo(100);
make.hugging.priorityRequired();
make.hugging.vertical.priorityRequired();
make.hugging.horizontal.priorityRequired();
make.compression.priorityRequired();
make.compression.vertical.priorityRequired();
make.compression.horizontal.priorityRequired();
make.vertical.hugging.priorityRequired();
make.vertical.compression.priorityRequired();
make.horizontal.hugging.priorityRequired();
make.horizontal.compression.priorityRequired();
}];
@nickynick @cloudkite
Solution: MASForbearance.zip

@iStarEternal
Copy link
Author

If it helps, please add it to Masonry

@adubr
Copy link

adubr commented Jul 4, 2016

Hey @robertjpayne,

I'd like to contribute to this issue and prepare a nice and clean PR. But first I'd like to discuss syntax, logic and probable caveats of the feature.

Some of the discussion was started at #88, and @nickynick with @cloudkite pointed out that hugging and compression resistance are somehow out of Mansonry semantics, which is kind of true. On the other hand as far as I know there are underlying constraints to support these properties, though they aren't available to the user directly. I suppose there could be a workaround, like storing the hugging and compression resistance values in an instance of a specialized subclass of MASConstraint and applying/rolling them back when appropriate (i.e. install and uninstall methods). How does it sound to you?

And what syntax looks good? The one suggested by @iStarEternal or the one from #88?

@iStarEternal
Copy link
Author

iStarEternal commented Jul 4, 2016

@adubr Nice to meet you! you can download my solution: MASForbearance.zip and try to use it.
I think it can perfectly solve my problem, I wish it could help you.

@robertjpayne
Copy link
Member

robertjpayne commented Aug 7, 2016

@adubr @iStarEternal it's an interesting feature, I think in some ways @cloudkite is right that semantically it doesn't make much sense to stuff these into the maker API.

One could say that a shortcut API would be beneficial, and it's what I've done in the Swift version.

view.mas_contentCompressionResistanceVerticalPriority = 50.0

The benefit here is getting rid of the method call and making it just a dynamic property.

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

No branches or pull requests

3 participants