Module: ProMotion::Tabs
- Included in:
- DelegateModule, ScreenModule
- Defined in:
- lib/ProMotion/tabs/tabs.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#tab_bar ⇒ Object
Returns the value of attribute tab_bar.
-
#tab_bar_item ⇒ Object
Returns the value of attribute tab_bar_item.
Class Method Summary collapse
Instance Method Summary collapse
- #create_tab_bar_item(tab = {}) ⇒ Object
- #create_tab_bar_item_custom(title, item_image, tag) ⇒ Object
- #current_tag ⇒ Object
- #map_tab_symbol(symbol) ⇒ Object
- #open_tab(tab) ⇒ Object
- #open_tab_bar(*screens) ⇒ Object
- #refresh_tab_bar_item ⇒ Object
- #replace_current_item(tab_bar_controller, view_controller: vc) ⇒ Object
- #set_tab_bar_badge(number) ⇒ Object
- #set_tab_bar_item(args = {}) ⇒ Object
Instance Attribute Details
#tab_bar ⇒ Object
Returns the value of attribute tab_bar.
3 4 5 |
# File 'lib/ProMotion/tabs/tabs.rb', line 3 def @tab_bar end |
#tab_bar_item ⇒ Object
Returns the value of attribute tab_bar_item.
3 4 5 |
# File 'lib/ProMotion/tabs/tabs.rb', line 3 def @tab_bar_item end |
Class Method Details
.included(base) ⇒ Object
118 119 120 |
# File 'lib/ProMotion/tabs/tabs.rb', line 118 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#create_tab_bar_item(tab = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ProMotion/tabs/tabs.rb', line 52 def (tab={}) if tab[:system_icon] mp("`system_icon:` no longer supported. Use `system_item:` instead.", force_color: :yellow) tab[:system_item] ||= tab[:system_icon] end if tab[:icon] mp("`icon:` no longer supported. Use `item:` instead.", force_color: :yellow) tab[:item] ||= tab[:icon] end unless tab[:system_item] || tab[:item] mp "You must provide either a `system_item:` or custom `item:` in `tab_bar_item`", force_color: :yellow abort end title = tab[:title] || "Untitled" = UITabBarItem.alloc.initWithTabBarSystemItem(map_tab_symbol(tab[:system_item]), tag: current_tag) if tab[:system_item] = (title, tab[:item], current_tag) if tab[:item] .badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0 .imageInsets = tab[:image_insets] if tab[:image_insets] end |
#create_tab_bar_item_custom(title, item_image, tag) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ProMotion/tabs/tabs.rb', line 33 def (title, item_image, tag) if item_image.is_a?(String) item_image = UIImage.imageNamed(item_image) elsif item_image.is_a?(Hash) item_selected = item_image[:selected] item_unselected = item_image[:unselected] item_image = nil end item = UITabBarItem.alloc.initWithTitle(title, image: item_image, tag: tag) if item_selected || item_unselected item.image = item_unselected item.selectedImage = item_selected end item end |
#current_tag ⇒ Object
79 80 81 82 |
# File 'lib/ProMotion/tabs/tabs.rb', line 79 def current_tag return @prev_tag = 0 unless @prev_tag @prev_tag += 1 end |
#map_tab_symbol(symbol) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ProMotion/tabs/tabs.rb', line 90 def map_tab_symbol(symbol) @_tab_symbols ||= { more: UITabBarSystemItemMore, favorites: UITabBarSystemItemFavorites, featured: UITabBarSystemItemFeatured, top_rated: UITabBarSystemItemTopRated, recents: UITabBarSystemItemRecents, contacts: UITabBarSystemItemContacts, history: UITabBarSystemItemHistory, bookmarks: UITabBarSystemItemBookmarks, search: UITabBarSystemItemSearch, downloads: UITabBarSystemItemDownloads, most_recent: UITabBarSystemItemMostRecent, most_viewed: UITabBarSystemItemMostViewed } @_tab_symbols[symbol] || symbol end |
#open_tab(tab) ⇒ Object
15 16 17 |
# File 'lib/ProMotion/tabs/tabs.rb', line 15 def open_tab(tab) self..open_tab(tab) end |
#open_tab_bar(*screens) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/ProMotion/tabs/tabs.rb', line 5 def (*screens) self. = PM::TabBarController.new(screens) self..pm_tab_delegate = WeakRef.new(self) delegate = self.respond_to?(:open_root_screen) ? self : UIApplication.sharedApplication.delegate delegate.open_root_screen(self.) self. end |
#refresh_tab_bar_item ⇒ Object
24 25 26 |
# File 'lib/ProMotion/tabs/tabs.rb', line 24 def self.tabBarItem = (self.) if self. && self.respond_to?("tabBarItem=") end |
#replace_current_item(tab_bar_controller, view_controller: vc) ⇒ Object
84 85 86 87 88 |
# File 'lib/ProMotion/tabs/tabs.rb', line 84 def replace_current_item(, view_controller: vc) controllers = NSMutableArray.arrayWithArray(.viewControllers) controllers.replaceObjectAtIndex(.selectedIndex, withObject: vc) .viewControllers = controllers end |
#set_tab_bar_badge(number) ⇒ Object
28 29 30 31 |
# File 'lib/ProMotion/tabs/tabs.rb', line 28 def (number) self.[:badge_number] = number end |
#set_tab_bar_item(args = {}) ⇒ Object
19 20 21 22 |
# File 'lib/ProMotion/tabs/tabs.rb', line 19 def (args = {}) self. = args end |