Module: ProMotion::ScreenTabs
- Included in:
- Delegate, ScreenModule
- Defined in:
- lib/ProMotion/screen_helpers/screen_tabs.rb
Instance Method Summary collapse
- #create_tab_bar_icon(icon, tag) ⇒ Object
- #create_tab_bar_icon_custom(title, image_name, tag) ⇒ Object
- #create_tab_bar_item(tab = {}) ⇒ Object
- #open_tab(tab) ⇒ Object
-
#open_tab_bar(*screens) ⇒ UITabBarController
Open a UITabBarController with the specified screens as the root view controller of the current app.
- #replace_current_item(tab_bar_controller, view_controller: vc) ⇒ Object
- #select(tab_bar_controller, title: title) ⇒ Object
- #tab_bar_controller(*screens) ⇒ Object
Instance Method Details
#create_tab_bar_icon(icon, tag) ⇒ Object
55 56 57 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 55 def (icon, tag) return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag) end |
#create_tab_bar_icon_custom(title, image_name, tag) ⇒ Object
59 60 61 62 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 59 def (title, image_name, tag) icon_image = UIImage.imageNamed(image_name) return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag) end |
#create_tab_bar_item(tab = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 64 def (tab={}) title = "Untitled" title = tab[:title] if tab[:title] tab[:tag] ||= @current_tag ||= 0 @current_tag = tab[:tag] + 1 = (tab[:system_icon], tab[:tag]) if tab[:system_icon] = (title, tab[:icon], tab[:tag]) if tab[:icon] .badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0 return end |
#open_tab(tab) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 44 def open_tab(tab) if tab.is_a? String return self.select(self., title: tab) elsif tab.is_a? Numeric .selectedIndex = tab return .viewControllers[tab] else $stderr.puts "Unable to open tab #{tab.to_s} because it isn't a string." end end |
#open_tab_bar(*screens) ⇒ UITabBarController
Open a UITabBarController with the specified screens as the root view controller of the current app.
35 36 37 38 39 40 41 42 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 35 def (*screens) = (*screens) a = self.respond_to?(:load_root_screen) ? self : UIApplication.sharedApplication.delegate a.load_root_screen() end |
#replace_current_item(tab_bar_controller, view_controller: vc) ⇒ Object
90 91 92 93 94 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 90 def replace_current_item(, view_controller: vc) controllers = NSMutableArray.arrayWithArray(.viewControllers) controllers.replaceObjectAtIndex(.selectedIndex, withObject: vc) .viewControllers = controllers end |
#select(tab_bar_controller, title: title) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 78 def select(, title: title) root_controller = nil .viewControllers.each do |vc| if vc.tabBarItem.title == title .selectedViewController = vc root_controller = vc break end end root_controller end |
#tab_bar_controller(*screens) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ProMotion/screen_helpers/screen_tabs.rb', line 3 def (*screens) = UITabBarController.alloc.init view_controllers = [] tag_index = 0 screens.map! { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes screens.each do |s| s = s.new if s.respond_to?(:new) s.tabBarItem.tag = tag_index s.parent_screen = self if self.is_a?(UIViewController) && s.respond_to?("parent_screen=") s. = if s.respond_to?("tab_bar=") vc = s.respond_to?(:main_controller) ? s.main_controller : s view_controllers << vc tag_index += 1 s.on_load if s.respond_to?(:on_load) end .viewControllers = view_controllers end |