module MotionHybrid::Navigatable
Public Instance Methods
content()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 14 def content NSURL.URLWithString(@initial_url) end
load_failed(error)
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 48 def load_failed(error) unless [102, -999].include?(error.code) #http://stackoverflow.com/questions/19487330/failed-to-load-webpage-error-nsurlerrordomain-error-999 stop_transitions on_error(error) if respond_to?(:on_error) PM.logger.warn error end end
load_finished()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 41 def load_finished @url = current_url stop_transitions load_bridge unless external_page? reload_dependents if needs_reload? end
load_started()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 36 def load_started @dom_loaded = false start_transitions end
on_request(nsurlrequest, type)
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 66 def on_request(nsurlrequest, type) process_request Request.new(nsurlrequest, type) end
open_url(url)
click to toggle source
overrides Promotion method to set more sensible timeout default
# File lib/motion-hybrid/concerns/navigatable.rb, line 77 def open_url(url) url = url.is_a?(NSURL) ? url : NSURL.URLWithString(url) request = NSURLRequest.requestWithURL(url, cachePolicy: NSURLRequestUseProtocolCachePolicy, timeoutInterval: 20) web.loadRequest request end
path()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 22 def path self.class.path_for(url) end
path=(path)
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 18 def path=(path) self.url = self.class.url_for(path) end
reset!()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 56 def reset! dismissModalViewControllerAnimated(false) return_to_root load_initial_url end
return_to_root()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 62 def return_to_root close to_screen: :root, animated: false if nav_bar? end
set_initial_content()
click to toggle source
Calls superclass method
# File lib/motion-hybrid/concerns/navigatable.rb, line 10 def set_initial_content super if @initial_url end
url()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 32 def url @url end
url=(url)
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 26 def url=(url) @url = url @initial_url ||= url open_url(url) if webview end
Private Instance Methods
external_page?()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 85 def external_page? !url.include?(self.class.root_url) end
load_initial_url()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 112 def load_initial_url self.path = self.class.path_for(@initial_url) end
process_request(request)
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 89 def process_request(request) return dom_loaded && false if request.url == 'motionhybrid://ready' @needs_reload = true if request.http_method != 'GET' if router.process(request) PM.logger.info("#{self} #{request} <intercept>") false else PM.logger.info("#{self} #{request} <load>") true end end
push(url, options = {})
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 102 def push(url, options = {}) screen = options.delete(:screen) || self.class view_options = options.slice!(:hide_tab_bar) options[:modal] = view_options[:modal] view_options.reverse_merge!(url: url, modal: modal?) new_view = screen.new(view_options) open(new_view, options) new_view end
router()
click to toggle source
# File lib/motion-hybrid/concerns/navigatable.rb, line 116 def router @router ||= Router.new(self) end