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-reloading of motion-kit layouts #777

Merged
merged 4 commits into from
Mar 29, 2016

Conversation

dchersey
Copy link
Contributor

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.

  1. To make this generic, would need to refactor Kernel in repl.rb to use a collection of LiveReloaders and provide a registration capability. This PR could them become a separate gem that uses this capability.
  2. Also looking into parsing the code of each ViewController and looking for references to the Layout class; this removes the need for naming convention.

Thoughts on the above items/any additional considerations?

@jamonholmgren
Copy link
Owner

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

@dchersey
Copy link
Contributor Author

That sounds simple enough. The method hook could fall back on the naming
solution so we have convention and configuration.

Should have something to look at tomorrow.
On Thu, Mar 17, 2016 at 4:20 PM Jamon Holmgren notifications@github.com
wrote:

@dchersey https://github.com/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?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#777 (comment)

@jamonholmgren
Copy link
Owner

Great, thanks!

@dchersey
Copy link
Contributor Author

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?

@dchersey
Copy link
Contributor Author

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.

@jamonholmgren
Copy link
Owner

Sorry about that, @dchersey ! Taking a look now...

@jamonholmgren jamonholmgren merged commit cca0632 into jamonholmgren:master Mar 29, 2016
@jamonholmgren
Copy link
Owner

Looks great! I'll include it in the next version of PM.

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.

2 participants