lib/ProMotion/screen/screen_module.rb in ProMotion-1.1.2 vs lib/ProMotion/screen/screen_module.rb in ProMotion-1.2.0
- old
+ new
@@ -1,5 +1,10 @@
+motion_require 'screen_navigation'
+motion_require '../view/styling'
+motion_require '../containers/tabs'
+motion_require '../containers/split_screen'
+
module ProMotion
module ScreenModule
include ProMotion::ScreenNavigation
include ProMotion::Styling
include ProMotion::Tabs
@@ -10,13 +15,15 @@
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)
+ resolve_title
+
self.tab_bar_item = self.class.send(:get_tab_bar_item)
self.refresh_tab_bar_item if self.tab_bar_item
+ self.class.send(:get_title)
args.each { |k, v| self.send("#{k}=", v) if self.respond_to?("#{k}=") }
self.add_nav_bar(args) if args[:nav_bar]
self.navigationController.toolbarHidden = !args[:toolbar] unless args[:toolbar].nil?
@@ -46,10 +53,22 @@
def navigationController=(nav)
@navigationController = nav
end
+ def resolve_title
+ if self.class.send(:get_title).kind_of? String
+ self.title = self.class.send(:get_title)
+ elsif self.class.send(:get_title).kind_of? UIView
+ self.navigationItem.titleView = self.class.send(:get_title)
+ elsif self.class.send(:get_title).kind_of? UIImage
+ self.navigationItem.titleView = UIImageView.alloc.initWithImage(self.class.send(:get_title))
+ else
+ PM.logger.warn("title expects string, UIView, or UIImage, but #{self.class.send(:get_title).class.to_s} given.")
+ end
+ end
+
def add_nav_bar(args = {})
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]
@@ -118,10 +137,14 @@
nil
end
end
end
+ def parent_screen=(parent)
+ @parent_screen = WeakRef.new(parent)
+ end
+
def first_screen?
self.first_screen == true
end
def view_did_load; end
@@ -280,9 +303,10 @@
@title = t
end
def title=(t)
@title = t
end
+
def get_title
@title ||= self.to_s
end
end