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

View controller support #7

Open
cfilipov opened this issue Sep 29, 2018 · 5 comments
Open

View controller support #7

cfilipov opened this issue Sep 29, 2018 · 5 comments

Comments

@cfilipov
Copy link

It is incredibly useful to have UIViewController styling support and I think this should be included. It's fairly easy to add (see this commit) and it even helps alleviate the problem with styling UITabBarItem as mentioned in #1 since you can do that from within the UIViewController style.

@werediver
Copy link
Owner

Supporting view controllers might be useful, indeed. It's less clear at which moment they should be styled, though.

Yes, viewDidLoad might be appropriate, but it would be quite different from UIView styling where didMoveToWindow is used (to mimic UIAppearance), so it happens rather late. viewDidLoad happens in contrast rather early. It might still be a convenient approach, because with UIKit it's common to do a lot of setup in this method.

I presume you have some experience with your implementation. Does it behave as you (or especially an abstract iOS developer) would expect? Any quirks?

If not, I'd start with integrating view controller support. Please note, that I'd like to support macOS as well (which your current implementation doesn't). Feel free to provide partial implementation, we can collaborate on this.

@cfilipov
Copy link
Author

The reason UIAppearance injects into didMoveToWindow is because there isn't any other reliable setup method in UIView to depend on. You can't be sure that an arbitrary UIView is setup and ready after init(frame:) or init(coder:), this is why UIAppearance is implemented the way it is. If UIView had a viewDidLoad method then I imagine they would have used that.

So far I haven't had any issues with injecting styles at viewDidLoad. I use it on every view controller in my app and also on apple's own view controllers and so far so good.

@cfilipov
Copy link
Author

I'll work on getting something working on macOS as well then create a PR for this.

@werediver
Copy link
Owner

The reason UIAppearance injects into didMoveToWindow is because there isn't any other reliable setup method in UIView to depend on. You can't be sure that an arbitrary UIView is setup and ready after init(frame:) or init(coder:), this is why UIAppearance is implemented the way it is. If UIView had a viewDidLoad method then I imagine they would have used that.

This reasoning completely ignores the existence of other methods such as willMove(toSuperview:), didMoveToSuperview(). But this topic doesn't require further discussion, as we have no issues with views.

Looking forward for you pull request.

@cfilipov
Copy link
Author

Good point. I think those methods would also have been good candidates.

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

2 participants