lib/ProMotion/tabs/tabs.rb in ProMotion-2.0.1 vs lib/ProMotion/tabs/tabs.rb in ProMotion-2.1.0.beta1

- old
+ new

@@ -36,40 +36,47 @@ item_selected = item_image[:selected] item_unselected = item_image[:unselected] item_image = nil end - item = UITabBarItem.alloc.initWithTitle(title, image:item_image, tag:tag) + item = UITabBarItem.alloc.initWithTitle(title, image: item_image, tag: tag) if item_selected || item_unselected item.setFinishedSelectedImage(item_selected, withFinishedUnselectedImage: item_unselected) end - return item + item end def create_tab_bar_item(tab={}) if tab[:system_icon] || tab[:icon] PM.logger.deprecated("`system_icon:` no longer supported. Use `system_item:` instead.") if tab[:system_icon] PM.logger.deprecated("`icon:` no longer supported. Use `item:` instead.") if tab[:icon] tab[:system_item] ||= tab[:system_icon] tab[:item] ||= tab[:icon] end - title = "Untitled" - title = tab[:title] if tab[:title] - tab[:tag] ||= @current_tag ||= 0 - @current_tag = tab[:tag] + 1 + unless tab[:system_item] || tab[:item] + PM.logger.warn("You must provide either a `system_item:` or custom `item:` in `tab_bar_item`") + abort + end - tab_bar_item = UITabBarItem.alloc.initWithTabBarSystemItem(map_tab_symbol(tab[:system_item]), tag: tab[:tag]) if tab[:system_item] - tab_bar_item = create_tab_bar_item_custom(title, tab[:item], tab[:tag]) if tab[:item] + title = tab[:title] || "Untitled" + tab_bar_item = UITabBarItem.alloc.initWithTabBarSystemItem(map_tab_symbol(tab[:system_item]), tag: current_tag) if tab[:system_item] + tab_bar_item = create_tab_bar_item_custom(title, tab[:item], current_tag) if tab[:item] + tab_bar_item.badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0 - return tab_bar_item + tab_bar_item end + def current_tag + return @prev_tag = 0 unless @prev_tag + @prev_tag += 1 + end + def replace_current_item(tab_bar_controller, view_controller: vc) controllers = NSMutableArray.arrayWithArray(tab_bar_controller.viewControllers) controllers.replaceObjectAtIndex(tab_bar_controller.selectedIndex, withObject: vc) tab_bar_controller.viewControllers = controllers end @@ -94,9 +101,10 @@ module TabClassMethods def tab_bar_item(args={}) @tab_bar_item = args end + def get_tab_bar_item @tab_bar_item end end