lib/ProMotion/screen/screen_module.rb in ProMotion-1.0.4 vs lib/ProMotion/screen/screen_module.rb in ProMotion-1.1.0.rc1
- old
+ new
@@ -31,24 +31,27 @@
def modal?
self.modal == true
end
def nav_bar?
- !!self.navigation_controller
+ !!self.navigationController
end
def navigation_controller
- @navigation_controller ||= self.navigationController
+ self.navigationController
end
- def navigation_controller=(val)
- @navigation_controller = val
- val
+ def navigation_controller=(nav)
+ @navigationController = nav
end
+ def navigationController=(nav)
+ @navigationController = nav
+ end
+
def add_nav_bar(args = {})
- self.navigation_controller ||= begin
+ self.navigationController ||= begin
self.first_screen = true if self.respond_to?(:first_screen=)
nav = NavigationController.alloc.initWithRootViewController(self)
nav.setModalTransitionStyle(args[:transition_style]) if args[:transition_style]
nav.setModalPresentationStyle(args[:presentation_style]) if args[:presentation_style]
nav
@@ -64,37 +67,53 @@
args[:title] = title
set_nav_bar_button :left, args
end
def set_nav_bar_button(side, args={})
+ button = create_toolbar_button(args)
+
+ self.navigationItem.leftBarButtonItem = button if side == :left
+ self.navigationItem.rightBarButtonItem = button if side == :right
+ self.navigationItem.backBarButtonItem = button if side == :back
+
+ button
+ end
+
+ def create_toolbar_button(args = {})
args[:style] = map_bar_button_item_style(args[:style])
args[:target] ||= self
args[:action] ||= nil
+ args[:custom_view] = args[:custom_view] if args[:custom_view]
args[:system_item] ||= args[:system_icon] # backwards compatibility
args[:system_item] = map_bar_button_system_item(args[:system_item]) if args[:system_item] && args[:system_item].is_a?(Symbol)
-
- button_type = args[:image] || args[:button] || args[:system_item] || args[:title] || "Button"
- button = bar_button_item button_type, args
+ button_type = args[:image] || args[:button] || args[:system_item] || args[:custom_view] || args[:title] || "Button"
- self.navigationItem.leftBarButtonItem = button if side == :left
- self.navigationItem.rightBarButtonItem = button if side == :right
+ bar_button_item button_type, args
+ end
- button
+ def set_toolbar_items(buttons = [], animated = true)
+ buttons = Array(buttons)
+ self.toolbarItems = buttons.map{|b| b.is_a?(UIBarButtonItem) ? b : create_toolbar_button(b) }
+ navigation_controller.setToolbarHidden(false, animated:animated)
end
-
+ alias_method :set_toolbar_buttons, :set_toolbar_items
+ alias_method :set_toolbar_button, :set_toolbar_items
+
# TODO: Make this better. Not able to do image: "logo", for example.
def bar_button_item(button_type, args)
case button_type
when UIBarButtonItem
button_type
when UIImage
UIBarButtonItem.alloc.initWithImage(button_type, style: args[:style], target: args[:target], action: args[:action])
when String
UIBarButtonItem.alloc.initWithTitle(button_type, style: args[:style], target: args[:target], action: args[:action])
else
- if args[:system_item]
+ if args[:custom_view]
+ UIBarButtonItem.alloc.initWithCustomView(args[:custom_view])
+ elsif args[:system_item]
UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_item], target: args[:target], action: args[:action])
else
PM.logger.error("Please supply a title string, a UIImage or :system.")
nil
end
@@ -206,19 +225,19 @@
end
def frame
return self.view_or_self.frame
end
-
+
def map_bar_button_item_style(symbol)
symbol = {
plain: UIBarButtonItemStylePlain,
bordered: UIBarButtonItemStyleBordered,
done: UIBarButtonItemStyleDone
}[symbol] if symbol.is_a?(Symbol)
symbol || UIBarButtonItemStyleBordered
end
-
+
def map_bar_button_system_item(symbol)
{
done: UIBarButtonSystemItemDone,
cancel: UIBarButtonSystemItemCancel,
edit: UIBarButtonSystemItemEdit,