class UnderOs::UI::Navbar

Constants

SYSTEM_BUTTONS

Attributes

_[R]

Public Class Methods

new(ui_navigation_controller) click to toggle source
# File lib/under_os/ui/navbar.rb, line 4
def initialize(ui_navigation_controller)
  @_ = ui_navigation_controller
end

Public Instance Methods

disable_swipes() click to toggle source
# File lib/under_os/ui/navbar.rb, line 27
def disable_swipes
  @_.interactivePopGestureRecognizer.enabled = false
end
enable_swipes() click to toggle source
# File lib/under_os/ui/navbar.rb, line 31
def enable_swipes
  @_.interactivePopGestureRecognizer.enabled = true
end
hidden() click to toggle source
# File lib/under_os/ui/navbar.rb, line 19
def hidden
  @_.navigationBarHidden
end
hide(animated=true) click to toggle source
# File lib/under_os/ui/navbar.rb, line 11
def hide(animated=true)
  @_.setNavigationBarHidden(true, animated:animated)
end
left_button() click to toggle source
# File lib/under_os/ui/navbar.rb, line 35
def left_button
  @left_button
end
left_button=(view) click to toggle source
# File lib/under_os/ui/navbar.rb, line 39
def left_button=(view)
  @left_button = view
  @_.topViewController.navigationItem.leftBarButtonItem = to_navigation_item(view)
end
repaint(stylesheet) click to toggle source
# File lib/under_os/ui/navbar.rb, line 8
def repaint(stylesheet)
end
right_button() click to toggle source
# File lib/under_os/ui/navbar.rb, line 44
def right_button
  right_buttons[0]
end
right_button=(view) click to toggle source
# File lib/under_os/ui/navbar.rb, line 48
def right_button=(view)
  self.right_buttons = [view]
end
right_buttons() click to toggle source
# File lib/under_os/ui/navbar.rb, line 52
def right_buttons
  @right_buttons || []
end
right_buttons=(views) click to toggle source
# File lib/under_os/ui/navbar.rb, line 56
def right_buttons=(views)
  views = [views] if views.is_a?(Hash)
  @right_buttons = views
  @_.topViewController.navigationItem.rightBarButtonItems =
    views.map{|v| to_navigation_item(v)}.flatten.compact.reverse
end
show(animated=true) click to toggle source
# File lib/under_os/ui/navbar.rb, line 15
def show(animated=true)
  @_.setNavigationBarHidden(false, animated:animated)
end
visible() click to toggle source
# File lib/under_os/ui/navbar.rb, line 23
def visible
  !hidden
end

Private Instance Methods

to_navigation_item(view) click to toggle source
# File lib/under_os/ui/navbar.rb, line 65
def to_navigation_item(view)
  view = to_raw_uiview(view)

  if view.is_a?(UIBarButtonItem)
    view
  elsif view.is_a?(UIView)
    UIBarButtonItem.alloc.initWithCustomView(view)
  elsif view.is_a?(Hash)
    view.map do |type, callback|
      if SYSTEM_BUTTONS[type.to_sym]
        UIBarButtonItem.alloc.initWithBarButtonSystemItem SYSTEM_BUTTONS[type.to_sym], target: callback, action: :call
      elsif type.is_a?(UIImage)
        UIBarButtonItem.alloc.initWithImage(type, style: UIBarButtonItemStylePlain, target: callback, action: :call)
      else
        UIBarButtonItem.alloc.initWithTitle(type.to_s, style: UIBarButtonItemStylePlain, target: callback, action: :call)
      end
    end
  end
end
to_raw_uiview(view) click to toggle source
# File lib/under_os/ui/navbar.rb, line 85
def to_raw_uiview(view)
  view = view.to_sym if view.is_a?(String)
  view = {view: Proc.new{}} if view.is_a?(Symbol)

  if view.is_a?(UnderOs::UI::View)
    view.addClass('navbar-item')
    view.repaint(UnderOs::App.history.current_page.stylesheet)
    view = view._
  end

  view
end