lib/ProMotion/screens/_screen_module.rb in ProMotion-0.5.2 vs lib/ProMotion/screens/_screen_module.rb in ProMotion-0.6.0

- old
+ new

@@ -2,25 +2,26 @@ module ScreenModule include ProMotion::ScreenNavigation include ProMotion::ScreenElements include ProMotion::SystemHelper include ProMotion::ScreenTabs + include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2") - attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal + attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal, :split_screen def on_create(args = {}) unless self.is_a?(UIViewController) raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.") end - + args.each do |k, v| self.send("#{k}=", v) if self.respond_to?("#{k}=") end self.add_nav_bar if args[:nav_bar] - self.table_setup if self.respond_to?(:table_setup) self.on_init if self.respond_to?(:on_init) + self.table_setup if self.respond_to?(:table_setup) self end def is_modal? self.modal == true @@ -52,32 +53,37 @@ def refresh_tab_bar_item self.tabBarItem = create_tab_bar_item(self.tab_bar_item) if self.tab_bar_item end def add_nav_bar - self.navigation_controller = NavigationController.alloc.initWithRootViewController(self) - self.first_screen = true + self.navigation_controller ||= begin + self.first_screen = true if self.respond_to?(:first_screen=) + NavigationController.alloc.initWithRootViewController(self) + end end def set_nav_bar_right_button(title, args={}) - args[:style] ||= UIBarButtonItemStyleBordered - args[:target] ||= self - args[:action] ||= nil - - right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action]) - self.navigationItem.rightBarButtonItem = right_button - right_button + args[:title] = title + set_nav_bar_button :right, args end def set_nav_bar_left_button(title, args={}) + args[:title] = title + set_nav_bar_button :left, args + end + + def set_nav_bar_button(side, args={}) args[:style] ||= UIBarButtonItemStyleBordered args[:target] ||= self args[:action] ||= nil - left_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action]) - self.navigationItem.leftBarButtonItem = left_button - left_button + button = UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action]) + + self.navigationItem.leftBarButtonItem = button if side == :left + self.navigationItem.rightBarButtonItem = button if side == :right + + button end # [DEPRECATED] def view_controller=(vc) set_view_controller(vc) @@ -97,28 +103,25 @@ def on_opened warn "[DEPRECATION] `on_opened` is deprecated. Please use `on_appear` instead." end def view_will_appear(animated) - # ProMotion::Screen.current_screen = self self.will_appear end def will_appear; end def view_did_appear(animated) - # ProMotion::Screen.current_screen = self self.on_appear end def on_appear; end def view_will_disappear(animated) self.will_disappear end def will_disappear; end def view_did_disappear(animated) - # ProMotion::Screen.current_screen = self.parent_screen if self.parent_screen self.on_disappear end def on_disappear; end def title @@ -129,12 +132,11 @@ self.class.title = new_title super end def main_controller - return self.navigation_controller if self.navigation_controller - self + self.navigation_controller || self end def view_controller warn "[DEPRECATION] `view_controller` is deprecated, as screens are now UIViewController subclasses." self @@ -168,44 +170,51 @@ def supported_orientation?(orientation) NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation) end def supported_orientations - ors = 0 + orientations = 0 NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori| case ori when "UIInterfaceOrientationPortrait" - ors |= UIInterfaceOrientationMaskPortrait + orientations |= UIInterfaceOrientationMaskPortrait when "UIInterfaceOrientationLandscapeLeft" - ors |= UIInterfaceOrientationMaskLandscapeLeft + orientations |= UIInterfaceOrientationMaskLandscapeLeft when "UIInterfaceOrientationLandscapeRight" - ors |= UIInterfaceOrientationMaskLandscapeRight + orientations |= UIInterfaceOrientationMaskLandscapeRight when "UIInterfaceOrientationPortraitUpsideDown" - ors |= UIInterfaceOrientationMaskPortraitUpsideDown + orientations |= UIInterfaceOrientationMaskPortraitUpsideDown end end - ors + orientations end + def supported_device_families + NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].map do |m| + case m + when "1" + :iphone + when "2" + :ipad + end + end + end + + def supported_device_family?(family) + supported_device_families.include?(family) + end + # Class methods module ClassMethods def debug_mode @debug_mode end def debug_mode=(v) @debug_mode = v end - def current_screen=(s) - @current_screen = s - end - - def current_screen - @current_screen - end - def title(t) @title = t end def title=(t) @title = t @@ -217,6 +226,6 @@ def self.included(base) base.extend(ClassMethods) end end -end \ No newline at end of file +end