-
Notifications
You must be signed in to change notification settings - Fork 148
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-reloading of motion-kit layouts #777
Conversation
@dchersey I like the idea of the generic plugin. Perhaps there could be a method hook for determining whether to reload a view controller, simply returning true or false, and pass in the reloaded file, the view controller(s), and the reloaded class name? |
That sounds simple enough. The method hook could fall back on the naming Should have something to look at tomorrow.
|
Great, thanks! |
Ok, first cut at generic registry is ready. This code works standalone - it's a refactor of the existing screen and view watchers. I've (for now) added code in my app_delegate to add layout monitoring as follows: layout_reloader = lambda do | opts |
is_layout = lambda do | vc, layout_code|
definition = layout_code.detect {|e| e =~ /class\s*(\S*)Layout/}
screen_name = "#{$1}Screen"
vc.class.to_s == screen_name
end
LiveReloader.new("app/layouts/**/*.rb", opts).watch do |reloaded_file, new_code, class_names|
vcs = pm_all_view_controllers(UIApplication.sharedApplication.delegate.window.rootViewController)
vcs.each do |vc|
if is_layout.(vc, class_names)
puts "Sending :on_live_reload to #{vc.inspect}." if opts[:debug]
vc.send(:on_live_reload) if vc.respond_to?(:on_live_reload)
end
end
end
end
Kernel.register_live_reloader layout_reloader Once we're merged, I will create a new gem motionkit-livereload containing this code. Or maybe just a PR for motionkit with a check to see if ProMotion is present - whatever Colin prefers. And I'll add the method hook too. Let me know what you think? |
Thoughts? I also noticed that live-reload does not affect screens opened modal. I can take a look at that too if I can figure out how to find them. |
Sorry about that, @dchersey ! Taking a look now... |
Looks great! I'll include it in the next version of PM. |
Referencing this issue from the motion-kit gem.
This implementation is pretty basic; it simply watches the app/layouts folder and reloads the view controller that matches Screen using class name.
Thoughts on the above items/any additional considerations?