module ProMotion::ScreenModule

Attributes

first_screen[RW]
modal[RW]
parent_screen[R]
screen_options[RW]
split_screen[RW]

Private Class Methods

included(base) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 245
def self.included(base)
  base.extend(ClassMethods)
  base.extend(StatusBarModule::ClassMethods)
  base.extend(Tabs::ClassMethods)
end

Public Instance Methods

add_child_screen(screen) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 151
def add_child_screen(screen)
  screen = screen.new if screen.respond_to?(:new)
  addChildViewController(screen)
  screen.parent_screen = self
  screen.didMoveToParentViewController(self) # Required
  screen
end
bounds() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 143
def bounds
  return self.view_or_self.bounds
end
did_receive_memory_warning() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 77
def did_receive_memory_warning
  self.on_memory_warning
end
first_screen?() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 35
def first_screen?
  self.first_screen == true
end
frame() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 147
def frame
  return self.view_or_self.frame
end
modal?() click to toggle source
on_appear() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 58
def on_appear; end
on_disappear() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 74
def on_disappear; end
on_dismiss() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 75
def on_dismiss; end
on_memory_warning() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 80
def on_memory_warning
  mp "Received memory warning in #{self.inspect}. You should implement on_memory_warning in your screen.", force_color: :red
end
on_present() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 59
def on_present; end
on_rotate() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 106
def on_rotate
end
parent_screen=(parent) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 31
def parent_screen=(parent)
  @parent_screen = WeakRef.new(parent)
end
remove_child_screen(screen) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 159
def remove_child_screen(screen)
  screen.parent_screen = nil
  screen.willMoveToParentViewController(nil) # Required
  screen.removeFromParentViewController
  screen
end
screen_init(args = {}) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 14
def screen_init(args = {})
  @screen_options = args
  check_ancestry
  resolve_title
  apply_properties(args)
  add_nav_bar(args)
  add_nav_bar_buttons
  tab_bar_setup
  try :on_init
  try :screen_setup
  mp "In #{self.class.to_s}, #on_create has been deprecated and removed. Use #screen_init instead.", force_color: :yellow if respond_to?(:on_create)
end
should_autorotate() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 102
def should_autorotate
  true
end
should_rotate(orientation) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 84
def should_rotate(orientation)
  case orientation
  when UIInterfaceOrientationPortrait
    return supported_orientation?("UIInterfaceOrientationPortrait")
  when UIInterfaceOrientationLandscapeLeft
    return supported_orientation?("UIInterfaceOrientationLandscapeLeft")
  when UIInterfaceOrientationLandscapeRight
    return supported_orientation?("UIInterfaceOrientationLandscapeRight")
  when UIInterfaceOrientationPortraitUpsideDown
    return supported_orientation?("UIInterfaceOrientationPortraitUpsideDown")
  else
    false
  end
end
supported_device_families() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 130
def supported_device_families
  NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].map do |m|
    {
      "1" => :iphone,
      "2" => :ipad
    }[m] || :unknown_device
  end
end
supported_device_family?(family) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 139
def supported_device_family?(family)
  supported_device_families.include?(family)
end
supported_orientation?(orientation) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 126
def supported_orientation?(orientation)
  NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
end
supported_orientations() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 109
def supported_orientations
  orientations = 0
  NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
    case ori
    when "UIInterfaceOrientationPortrait"
      orientations |= UIInterfaceOrientationMaskPortrait
    when "UIInterfaceOrientationLandscapeLeft"
      orientations |= UIInterfaceOrientationMaskLandscapeLeft
    when "UIInterfaceOrientationLandscapeRight"
      orientations |= UIInterfaceOrientationMaskLandscapeRight
    when "UIInterfaceOrientationPortraitUpsideDown"
      orientations |= UIInterfaceOrientationMaskPortraitUpsideDown
    end
  end
  orientations
end
view_did_appear(animated) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 53
def view_did_appear(animated)
  self.on_appear

  self.on_present if isMovingToParentViewController
end
view_did_disappear(animated) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 69
def view_did_disappear(animated)
  self.on_disappear

  self.on_dismiss if isMovingFromParentViewController
end
view_did_load() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 39
def view_did_load
  self.send(:on_load) if self.respond_to?(:on_load)
end
view_will_appear(animated) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 43
def view_will_appear(animated)
  update_nav_bar_visibility(animated)

  self.will_appear

  self.will_present if isMovingToParentViewController
end
view_will_disappear(animated) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 61
def view_will_disappear(animated)
  self.will_disappear

  self.will_dismiss if isMovingFromParentViewController
end
will_appear() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 50
def will_appear; end
will_disappear() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 66
def will_disappear; end
will_dismiss() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 67
def will_dismiss; end
will_present() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 51
def will_present; end
will_rotate(orientation, duration) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 99
def will_rotate(orientation, duration)
end

Private Instance Methods

add_nav_bar_buttons() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 178
def add_nav_bar_buttons
  self.class.get_nav_bar_button.each do |button_args|
    set_nav_bar_button(button_args[:side], button_args)
  end
end
apply_properties(args) click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 184
def apply_properties(args)
  reserved_args = [ :nav_bar, :nav_controller, :hide_nav_bar, :hide_tab_bar, :animated, :close_all, :replace_nav_stack, :in_tab, :in_detail, :in_master, :to_screen, :toolbar ]
  set_attributes self, args.dup.delete_if { |k,v| reserved_args.include?(k) }
end
check_ancestry() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 194
def check_ancestry
  unless self.is_a?(UIViewController)
    raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
  end
end
resolve_title() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 168
def resolve_title
  case self.class.title_type
  when :text then self.title = self.class.title
  when :view then self.navigationItem.titleView = self.class.title
  when :image then self.navigationItem.titleView = UIImageView.alloc.initWithImage(self.class.title)
  else
    mp("title expects string, UIView, or UIImage, but #{self.class.title.class.to_s} given.", force_color: :yellow)
  end
end
tab_bar_setup() click to toggle source
# File lib/ProMotion/screen/screen_module.rb, line 189
def tab_bar_setup
  self.tab_bar_item = self.class.send(:get_tab_bar_item)
  self.refresh_tab_bar_item if self.tab_bar_item
end