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

Make Code Injection Working For UI #2

Merged
merged 9 commits into from Aug 22, 2017
Merged

Conversation

bolismauro
Copy link
Contributor

@bolismauro bolismauro commented Aug 14, 2017

I have the strong feeling that if we manage to have a quick-to-setup injection when it comes to UI, we can drastically reduce the amount of time it takes to styles application, as we can live reloads tweaks without recompiling the swift project, which can be extremely slow for large applications.

Unfortunately, the code injection doesn't work for generic classes, as these are not exposed to the objc runtime and therefore cannot be dynamically reloaded. Tempura heavily uses generic classes and in particular the ModellableView is a generic subclass of UIView

Me and @smaramba decided to have two separated branches. Master will keep the generic class approach, while this branch will try the PAT path. Video Editor will use the master branch while VPN (if we decide to use tempura) will use this branch. After some time we will evaluate pros/cons of the two approaches and we will decide which is the best approach.

There are 3 steps I want to follow to try this approach:
1 - Refactor the project so that ModellableView is a PAT (DONE)
2 - Reduce the boilerplate introduced by the fact that we use a PAT and not a subclass (DONE)
3 - Find a method to make live reload works out of the box in the UI (DONE)

One of the biggest challenges will be to keep this branch in sync feature-wise with master.

@bolismauro
Copy link
Contributor Author

I can't find an elegant way to avoid to write

  override func layoutSubviews() {
    super.layoutSubviews()
    self.layout()
  }

every time.

Help is welcome :)

@bolismauro bolismauro changed the title [WIP] Make Code Injection Working For UI Make Code Injection Working For UI Aug 18, 2017
@bolismauro
Copy link
Contributor Author

bolismauro commented Aug 18, 2017

SUCCESS!!! 🚀

In the app delegate invoke

LiveReloadManager.shared.liveReloadViews(in: self.window!)

In your ModellableView instances, everything works out of the box. Update and Layout are automatically invoked. There are a couple extension points for particular cases (e.g., extra checks to invalidate to reload the view and so on).

For views that are not ModellableView it is enough to adopt the LiveReloadableView protocol and implement the method.

No XCode plugins, nor project changes are required (unlike the old version I've implemented in objc). It is enough to download this app
http://johnholdsworth.com/injection.html

Clean build -> run the project
then make a change in a view, press ctrl+=
If everything is ok and no errors are shown, from that moment on every time you save the file the live reload works for the view(s) you have open in xcode

That's it :D

@bolismauro
Copy link
Contributor Author

@lucaquerella @smaramba @frankdilo @sroddy
Please let me know your opinion :)

The only point to fix is the layoutSubviews method that must be implemented every time, which is annoying

@smaramba
Copy link
Contributor

my last commits address the issue with layout() method that needs to be implemented every.
Essentially I propose to use the layoutSubviews() method to do the actual layout instead of implement it just to invoke the layout method.
What do you think? @bolismauro @lucaquerella @sroddy

@bolismauro
Copy link
Contributor Author

SGTM

@smaramba smaramba merged commit 5075183 into master Aug 22, 2017
@smaramba smaramba deleted the feature/allow-injection branch August 22, 2017 15:48
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

2 participants