Skip to content

View controller support #7

Open

Description

@cfilipov

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.

Activity

  1. werediver commented on Sep 30, 2018

    @werediver
    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.

  2. cfilipov commented on Sep 30, 2018

    @cfilipov
    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.

  3. cfilipov commented on Sep 30, 2018

    @cfilipov
    Author

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

  4. werediver commented on Sep 30, 2018

    @werediver
    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.

  5. cfilipov commented on Sep 30, 2018

    @cfilipov
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions