lib/ProMotion/screens/_screen_module.rb in ProMotion-0.6.5 vs lib/ProMotion/screens/_screen_module.rb in ProMotion-0.7.0
- old
+ new
@@ -11,31 +11,41 @@
def on_create(args = {})
unless self.is_a?(UIViewController)
raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
end
-
self.title = self.class.send(:get_title)
args.each do |k, v|
self.send("#{k}=", v) if self.respond_to?("#{k}=")
end
self.add_nav_bar if args[:nav_bar]
+ self.navigationController.toolbarHidden = !args[:toolbar] unless args[:toolbar].nil?
self.on_init if self.respond_to?(:on_init)
self.table_setup if self.respond_to?(:table_setup)
self
end
def is_modal?
+ PM.logger.deprecated "`is_modal?` is deprecated. Use `modal?`."
+ modal?
+ end
+
+ def modal?
self.modal == true
end
def has_nav_bar?
- self.navigation_controller.nil? != true
+ PM.logger.deprecated "`has_nav_bar? is deprecated. Use `nav_bar?`."
+ nav_bar?
end
+ def nav_bar?
+ !!self.navigation_controller
+ end
+
def navigation_controller
@navigation_controller ||= self.navigationController
end
def navigation_controller=(val)
@@ -43,11 +53,11 @@
val
end
# [DEPRECATED]
def load_view_controller
- warn "[DEPRECATION] `load_view_controller` is deprecated and doesn't actually do anything anymore. You can safely remove it from your code."
+ PM.logger.deprecated "`load_view_controller` is deprecated and doesn't actually do anything anymore. You can safely remove it from your code."
end
def set_tab_bar_item(args = {})
self.tab_bar_item = args
refresh_tab_bar_item
@@ -72,36 +82,41 @@
def set_nav_bar_left_button(title, args={})
args[:title] = title
set_nav_bar_button :left, args
end
- # If you call set_nav_bar_button with a nil title and system_icon: UIBarButtonSystemItemAdd (or any other
- # system icon), the button is initialized with a barButtonSystemItem instead of a title.
def set_nav_bar_button(side, args={})
args[:style] ||= UIBarButtonItemStyleBordered
args[:target] ||= self
args[:action] ||= nil
+ button_type = args[:image] || args[:button] || args[:system_icon] || args[:title] || "Button"
- button = case args[:title]
- when String
- UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action])
- when UIImage
- UIBarButtonItem.alloc.initWithImage(args[:title], style: args[:style], target: args[:target], action: args[:action])
- when Symbol, NilClass
- UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], target: args[:target], action: args[:action]) if args[:system_icon]
- when UIBarButtonItem
- args[:title]
- else
- PM.logger.error("Please supply a title string, a UIImage or :system.")
- end
+ button = bar_button_item button_type, args
self.navigationItem.leftBarButtonItem = button if side == :left
self.navigationItem.rightBarButtonItem = button if side == :right
button
end
+ 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_icon]
+ UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], target: args[:target], action: args[:action])
+ else
+ PM.logger.error("Please supply a title string, a UIImage or :system.")
+ end
+ end
+ end
+
# [DEPRECATED]
def view_controller=(vc)
set_view_controller(vc)
end
@@ -114,13 +129,10 @@
warn "[DEPRECATION] `set_view_controller` is deprecated and discontinued. Please inherit from the UIViewController you wish to use and include ProMotion::ScreenViewController instead."
self
end
def view_did_load; end
- def on_opened
- warn "[DEPRECATION] `on_opened` is deprecated. Please use `on_appear` instead."
- end
def view_will_appear(animated)
self.will_appear
end
def will_appear; end
@@ -191,9 +203,10 @@
orientations
end
def supported_device_families
NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].map do |m|
+ # TODO: What about universal apps?
case m
when "1"
:iphone
when "2"
:ipad