Module: MotionPrime::ScreenNavigationBarMixin

Defined in:
motion-prime/screens/extensions/_navigation_bar_mixin.rb

Instance Method Summary collapse

Instance Method Details

#create_navigation_button(title, args = {}) ⇒ Object



43
44
45
46
47
48
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 43

def create_navigation_button(title, args = {})
  args[:style]  ||= UIBarButtonItemStylePlain
  args[:action] ||= nil
  # TODO: Find better place for this code, may be just create custom control
  if args[:image]
    image = args[:image].uiimage
    face = UIButton.buttonWithType UIButtonTypeCustom
    face.bounds = CGRectMake(0, 0, image.size.width, image.size.height)
    face.setImage image, forState: UIControlStateNormal
    face.on :touch do
      args[:action].to_proc.call(self)
    end
    UIBarButtonItem.alloc.initWithCustomView(face)
  elsif args[:icon]
    image = args[:icon].uiimage
    face = UIButton.buttonWithType UIButtonTypeCustom
    face.setImage(image, forState: UIControlStateNormal)
    face.setTitle(title, forState: UIControlStateNormal)
    face.bounds = CGRectMake(0, 0, 100, 60)
    face.setContentHorizontalAlignment UIControlContentHorizontalAlignmentLeft
    face.on :touch do
      args[:action].to_proc.call(self)
    end
    UIBarButtonItem.alloc.initWithCustomView(face)
  else
    UIBarButtonItem.alloc.initWithTitle(title,
      style: args[:style], target: args[:target] || self, action: args[:action])
  end
end


7
8
9
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 7

def navigation_left_button
  navigationItem.leftBarButtonItem
end


3
4
5
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 3

def navigation_right_button
  navigationItem.rightBarButtonItem
end

#remove_navigation_right_button(args = {}) ⇒ Object



11
12
13
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 11

def remove_navigation_right_button(args = {})
  navigationItem.setRightBarButtonItem(nil, animated: args[:animated])
end

#set_navigation_back_button(title, args = {}) ⇒ Object



23
24
25
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 23

def set_navigation_back_button(title, args = {})
  navigationItem.leftBarButtonItem = create_navigation_button(title, {action: :back}.merge(args))
end

#set_navigation_back_or_menu(back_title = 'Back') ⇒ Object

should be extracted to sidebar gem



28
29
30
31
32
33
34
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 28

def set_navigation_back_or_menu(back_title = 'Back')
  if parent_screen.is_a?(PrimeResideMenu::SidebarContainerScreen)
    set_navigation_left_button 'Menu', image: 'images/navigation/menu_button.png', action: :show_sidebar
  else
    set_navigation_back_button back_title, icon: 'images/navigation/back_icon.png'
  end
end

#set_navigation_left_button(title, args = {}) ⇒ Object



19
20
21
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 19

def set_navigation_left_button(title, args = {})
  navigationItem.leftBarButtonItem = create_navigation_button(title, args)
end

#set_navigation_right_button(title, args = {}) ⇒ Object



15
16
17
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 15

def set_navigation_right_button(title, args = {})
  navigationItem.rightBarButtonItem = create_navigation_button(title, args)
end

#set_navigation_right_image(args = {}) ⇒ Object



36
37
38
39
40
41
# File 'motion-prime/screens/extensions/_navigation_bar_mixin.rb', line 36

def set_navigation_right_image(args = {})
  url = args.delete(:url)
  view = add_view(UIImageView, args)
  view.setImageWithURL NSURL.URLWithString(url), placeholderImage: nil
  navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithCustomView(view)
end