lib/routable/router.rb in routable-0.1.1 vs lib/routable/router.rb in routable-0.2
- old
+ new
@@ -45,10 +45,12 @@
# OPTIONS
# :modal => true/false
# - We present the VC modally (router is not shared between the new nav VC)
# :shared => true/false
# - If URL is called again, we pop to that VC if it's in memory.
+ # :resets => true/false
+ # - Resets the navigation stack with the target view controller
# :transition => [:cover, :flip, :dissolve, :curl]
# - A symbol to represented transition style used. Mapped to UIModalTransitionStyle.
# :presentation => [:full_screen, :page_sheet, :form_sheet, :current]
# - A symbol to represented presentation style used. Mapped to UIModalPresentationStyle.
def map(url, klass = nil, options = {}, &callback)
@@ -67,15 +69,23 @@
end
self.routes[format] = options.merge!(klass: klass)
end
+ # Open the given URL via the iOS protocol
+ # EX
+ # router.open_external("http://google.com")
+ # => Opens Google in Safari.app
+ def open_external(url)
+ UIApplication.sharedApplication.openURL(NSURL.URLWithString(url))
+ end
+
# Push the UIViewController for the given url
# EX
# router.open("users/3")
# => router.navigation_controller pushes a UsersController
- def open(url, animated = true)
+ def open(url, animated = true, &block)
controller_options = options_for_url(url)
if controller_options[:callback]
params = controller_options[:open_params]
callback = controller_options[:callback]
@@ -87,14 +97,32 @@
end
return
end
controller = controller_for_url(url)
+
+ # Allow configuration of the view controller after
+ # initialization but before navigating to the view controller
+ if block_given?
+ block.call(controller)
+ end
+
if self.navigation_controller.modalViewController
- self.navigation_controller.dismissModalViewControllerAnimated(animated)
+ dismiss_animated = animated
+
+ # Can't dismiss and present two controllers animated at the same time,
+ # so we just dismiss the current one without an animation
+ if controller_options[:modal] && dismiss_animated
+ dismiss_animated = false
+ end
+
+ self.navigation_controller.dismissModalViewControllerAnimated(dismiss_animated)
end
- if controller_options[:modal]
+
+ if controller_options[:resets]
+ navigation_controller.setViewControllers([controller], animated: animated)
+ elsif controller_options[:modal]
if controller.class == UINavigationController
self.navigation_controller.presentModalViewController(controller, animated: animated)
else
tempNavigationController = UINavigationController.alloc.init
tempNavigationController.pushViewController(controller, animated: false)
@@ -229,6 +257,6 @@
def shared_vc_cache
@shared_vc_cache ||= {}
end
end
-end
\ No newline at end of file
+end