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

Live reload possible in some way? #35

Closed
olegam opened this issue Dec 14, 2013 · 12 comments
Closed

Live reload possible in some way? #35

olegam opened this issue Dec 14, 2013 · 12 comments

Comments

@olegam
Copy link
Contributor

olegam commented Dec 14, 2013

After I started using classy.as for my styling I have quickly become addicted to the live reloading feature. I'm thinking if we could somehow do something similar for Masonry it would be awesome. I don't know how this would work thought.

It's mostly my constant numbers I would like to change live. Today I use DCIntrospect (https://github.com/lukaswelte/DCIntrospect-ARC) to adjust frames in the simulator and then I have to remember the new constant values and change them in the code afterwards.

Could we define all constants in a separate file that is watched by Masonry. So that changes in the constant file would be injected into the running simulator?

@cloudkite
Copy link
Contributor

If you are doing your layout in custom UIView subclasses then you can already take advantage of live reload by using Classy to set the constants of your constraints. You would need to turn your constants into properties on your view class.

custom UIView subclass:

@interface MYCustomView : UIView

@property (nonatomic, assign) UIOffset someOffset

@end
@implementation MYCustomView

- (void)setSomeOffset:(UIOffset)someOffset {
   _someOffset = someOffset
   [self setNeedsUpdateConstraints];
}

- (void)updateConstraints {
   [super updateConstraints];

   [self.someView mas_updateConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self).with.offset(self.someOffset.vertical);
      make.left.equalTo(self).with.offset(self.someOffset.horizontal);
  }];
}

@end

in classy stylesheet

MYCustomView {
  someOffset 10, 5
}

Let me know how you get on 👍

@olegam
Copy link
Contributor Author

olegam commented Dec 15, 2013

Thats a great idea! Would be nice to be able to use it everywhere (also when not doing subclasses) and without the boilerplate. Maybe I can do categories on UIView and UIControl to give them new margin and size properties that will be stored in an ascociated object and in the setter call -setNeedsDisplay on the super view. I'll try to explore this :)

@olegam
Copy link
Contributor Author

olegam commented Dec 15, 2013

Seems to work very well with a UIView category to specify optional size and margin that can be referenced from the mas_updateConstraints method. Check out my example here: https://github.com/olegam/LiveLayoutDemo

What do you think of this approach? Something that would be suitable to ship wit Classy?

@cloudkite
Copy link
Contributor

Glad it's working for you 👍
In terms of including it in classy I have some reservations, as I would rather not make classy and masonry dependent on each other for people who want to use one and not the other.

Also most of the time I would recommend using a custom UIView subclass so that you keep view logic out of your UIViewControllers.

@olegam
Copy link
Contributor Author

olegam commented Dec 16, 2013

Ok cool. And thanks again for the advice. I think I will then make a small pod with the category and write a blog post about the approach.

@cloudkite
Copy link
Contributor

Sounds great! Looking forward to it :)

@lluisgerard
Copy link
Contributor

Looking forward too 👍 please, publish the link here, I love Masonry and is always nice to see how others use it!

@olegam
Copy link
Contributor Author

olegam commented Dec 17, 2013

@cloudkite
Copy link
Contributor

Thanks @olegam!

@lluisgerard
Copy link
Contributor

Amazing, thanks @olegam! 👍

@vascoorey
Copy link
Contributor

Awesome one, cheers @olegam !

@twlopes
Copy link

twlopes commented Dec 20, 2013

Very cool @olegam !

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

5 participants