Module: MotionPrime::ScreenNavigationBarMixin
- Included in:
- Screen
- Defined in:
- motion-prime/screens/extensions/_navigation_bar_mixin.rb
Instance Method Summary collapse
- #create_navigation_button(title, args = {}, &block) ⇒ Object
- #create_navigation_button_with_image(title, args) ⇒ Object
- #create_navigation_button_with_title(title, args) ⇒ Object
- #navigation_left_button ⇒ Object
- #navigation_right_button ⇒ Object
- #remove_navigation_right_button(args = {}) ⇒ Object
- #set_navigation_back_button(title, args = {}) ⇒ Object
-
#set_navigation_back_or_menu(back_title = 'Back') ⇒ Object
should be extracted to sidebar gem.
- #set_navigation_left_button(title, args = {}, &block) ⇒ Object
- #set_navigation_right_button(title, args = {}, &block) ⇒ Object
- #set_navigation_right_buttons(options) ⇒ Object
- #set_navigation_right_image(args = {}) ⇒ Object
Instance Method Details
#create_navigation_button(title, args = {}, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 49 def (title, args = {}, &block) args[:style] ||= UIBarButtonItemStylePlain args[:action] ||= block || nil # TODO: Find better place for this code, may be just create custom control if title.is_a?(UIButton) title.on :touch do args[:action].to_proc.call(args[:target] || self) end if args[:action] title.sizeToFit UIBarButtonItem.alloc.initWithCustomView(title) elsif args[:image] (title, args) elsif args[:icon] (title, args) else if args[:action].is_a?(Proc) (title, args) else UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target] || self, action: args[:action]) end end end |
#create_navigation_button_with_image(title, args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 87 def (title, args) face = UIButton. UIButtonTypeCustom if ui_image = args[:image].uiimage ui_image = ui_image.imageWithRenderingMode(2) if args[:tint_color].present? face.bounds = CGRectMake(0, 0, ui_image.size.width, ui_image.size.height) face.setImage ui_image, forState: UIControlStateNormal end face.setTintColor(args[:tint_color].uicolor) if args[:tint_color] face.setImageEdgeInsets(UIEdgeInsetsMake(0, args[:offset_x], 0, -args[:offset_x])) if args[:offset_x] face.on :touch do args[:action].to_proc.call(args[:target] || self) end if args[:action] UIBarButtonItem.alloc.initWithCustomView(face) end |
#create_navigation_button_with_title(title, args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 73 def (title, args) ui_image = args[:icon].uiimage if args[:icon] face = UIButton. UIButtonTypeCustom face.setImage(ui_image, forState: UIControlStateNormal) if ui_image face.setTitle(title, forState: UIControlStateNormal) face.setTitleColor((args[:title_color] || :app_navigation_base).uicolor, forState: UIControlStateNormal) face.setContentHorizontalAlignment UIControlContentHorizontalAlignmentLeft face.sizeToFit face.on :touch do args[:action].to_proc.call(args[:target] || self) end if args[:action] UIBarButtonItem.alloc.initWithCustomView(face) end |
#navigation_left_button ⇒ Object
7 8 9 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 7 def .leftBarButtonItem end |
#navigation_right_button ⇒ Object
3 4 5 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 3 def .rightBarButtonItem end |
#remove_navigation_right_button(args = {}) ⇒ Object
11 12 13 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 11 def (args = {}) .setRightBarButtonItem(nil, animated: args[:animated]) end |
#set_navigation_back_button(title, args = {}) ⇒ Object
29 30 31 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 29 def (title, args = {}) .leftBarButtonItem = (title, {action: :back}.merge(args)) end |
#set_navigation_back_or_menu(back_title = 'Back') ⇒ Object
should be extracted to sidebar gem
34 35 36 37 38 39 40 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 34 def (back_title = 'Back') if parent_screen.is_a?(PrimeResideMenu::SidebarContainerScreen) 'Menu', image: 'images/navigation/menu_button.png', action: :show_sidebar else back_title, icon: 'images/navigation/back_icon.png' end end |
#set_navigation_left_button(title, args = {}, &block) ⇒ Object
25 26 27 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 25 def (title, args = {}, &block) .leftBarButtonItem = (title, args, &block) end |
#set_navigation_right_button(title, args = {}, &block) ⇒ Object
15 16 17 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 15 def (title, args = {}, &block) .rightBarButtonItem = (title, args, &block) end |
#set_navigation_right_buttons(options) ⇒ Object
19 20 21 22 23 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 19 def () .rightBarButtonItems = .map do || (.delete(:title), ) end end |
#set_navigation_right_image(args = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 42 def (args = {}) url = args.delete(:url) view = add_view(UIImageView, args) view.setImageWithURL NSURL.URLWithString(url), placeholderImage: nil .rightBarButtonItem = UIBarButtonItem.alloc.initWithCustomView(view) end |