Module: ProMotion::ScreenModule

Includes:
ScreenElements, ScreenNavigation, ScreenTabs, SystemHelper
Included in:
Screen, TableScreenModule
Defined in:
lib/ProMotion/screen/_screen_module.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ScreenTabs

#create_tab_bar_icon, #create_tab_bar_icon_custom, #create_tab_bar_item, #open_tab, #open_tab_bar, #replace_current_item, #select, #tab_bar_controller

Methods included from SystemHelper

ios_version, ios_version_greater?, ios_version_greater_eq?, ios_version_is?, ios_version_less?, ios_version_less_eq?

Methods included from ScreenElements

#add_view, #bounds, #content_height, #frame, #remove_view

Methods included from ViewHelper

#content_height, #frame_from_array, #set_attributes

Methods included from ScreenNavigation

#app_delegate, #close_screen, #open_root_screen, #open_screen, #open_view_controller, #push_view_controller

Instance Attribute Details

#first_screenObject

Returns the value of attribute first_screen.



8
9
10
# File 'lib/ProMotion/screen/_screen_module.rb', line 8

def first_screen
  @first_screen
end

Returns the value of attribute modal.



8
9
10
# File 'lib/ProMotion/screen/_screen_module.rb', line 8

def modal
  @modal
end

#parent_screenObject

Returns the value of attribute parent_screen.



8
9
10
# File 'lib/ProMotion/screen/_screen_module.rb', line 8

def parent_screen
  @parent_screen
end

#tab_barObject

Returns the value of attribute tab_bar.



8
9
10
# File 'lib/ProMotion/screen/_screen_module.rb', line 8

def tab_bar
  @tab_bar
end

#tab_bar_itemObject

Returns the value of attribute tab_bar_item.



8
9
10
# File 'lib/ProMotion/screen/_screen_module.rb', line 8

def tab_bar_item
  @tab_bar_item
end

Class Method Details

.included(base) ⇒ Object



218
219
220
# File 'lib/ProMotion/screen/_screen_module.rb', line 218

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#add_nav_barObject



56
57
58
59
# File 'lib/ProMotion/screen/_screen_module.rb', line 56

def add_nav_bar
  self.navigation_controller = NavigationController.alloc.initWithRootViewController(self)
  self.first_screen = true
end

#first_screen?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/ProMotion/screen/_screen_module.rb', line 86

def first_screen?
  self.first_screen == true
end

#has_nav_bar?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ProMotion/screen/_screen_module.rb', line 29

def has_nav_bar?
  self.navigation_controller.nil? != true
end

#is_modal?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ProMotion/screen/_screen_module.rb', line 25

def is_modal?
  self.modal == true
end

#load_view_controllerObject

DEPRECATED


43
44
45
# File 'lib/ProMotion/screen/_screen_module.rb', line 43

def load_view_controller
  warn "[DEPRECATION] `load_view_controller` is deprecated and doesn't actually do anything anymore. You can safely remove it from your code."
end

#main_controllerObject



133
134
135
136
# File 'lib/ProMotion/screen/_screen_module.rb', line 133

def main_controller
  return self.navigationController if self.navigationController
  self
end


33
34
35
# File 'lib/ProMotion/screen/_screen_module.rb', line 33

def navigation_controller
  @navigation_controller ||= self.navigationController
end


37
38
39
40
# File 'lib/ProMotion/screen/_screen_module.rb', line 37

def navigation_controller=(val)
  @navigation_controller = val
  val
end

#on_appearObject



111
# File 'lib/ProMotion/screen/_screen_module.rb', line 111

def on_appear; end

#on_create(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ProMotion/screen/_screen_module.rb', line 10

def on_create(args = {})
  unless self.is_a?(UIViewController)
    raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
  end
  
  args.each do |k, v|
    self.send("#{k}=", v) if self.respond_to?("#{k}=")
  end

  self.add_nav_bar if args[:nav_bar]
  self.table_setup if self.respond_to?(:table_setup)      
  self.on_init if self.respond_to?(:on_init)
  self
end

#on_disappearObject



122
# File 'lib/ProMotion/screen/_screen_module.rb', line 122

def on_disappear; end

#on_openedObject



97
98
99
# File 'lib/ProMotion/screen/_screen_module.rb', line 97

def on_opened
  warn "[DEPRECATION] `on_opened` is deprecated.  Please use `on_appear` instead."
end

#on_rotateObject



165
166
# File 'lib/ProMotion/screen/_screen_module.rb', line 165

def on_rotate
end

#refresh_tab_bar_itemObject



52
53
54
# File 'lib/ProMotion/screen/_screen_module.rb', line 52

def refresh_tab_bar_item
  self.tabBarItem = create_tab_bar_item(self.tab_bar_item) if self.tab_bar_item
end

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



71
72
73
74
75
76
77
78
79
# File 'lib/ProMotion/screen/_screen_module.rb', line 71

def set_nav_bar_left_button(title, args={})
  args[:style]  ||= UIBarButtonItemStyleBordered
  args[:target] ||= self
  args[:action] ||= nil

  left_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
  self.navigationItem.leftBarButtonItem = left_button
  left_button
end

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



61
62
63
64
65
66
67
68
69
# File 'lib/ProMotion/screen/_screen_module.rb', line 61

def set_nav_bar_right_button(title, args={})
  args[:style]  ||= UIBarButtonItemStyleBordered
  args[:target] ||= self
  args[:action] ||= nil

  right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
  self.navigationItem.rightBarButtonItem = right_button
  right_button
end

#set_tab_bar_item(args = {}) ⇒ Object



47
48
49
50
# File 'lib/ProMotion/screen/_screen_module.rb', line 47

def set_tab_bar_item(args = {})
  self.tab_bar_item = args
  refresh_tab_bar_item
end

#set_view_controller(vc) ⇒ Object

DEPRECATED


91
92
93
94
# File 'lib/ProMotion/screen/_screen_module.rb', line 91

def set_view_controller(vc)
  warn "[DEPRECATION] `set_view_controller` is deprecated and discontinued.  Please inherit from the UIViewController you wish to use and include ProMotion::ScreenViewController instead."
  self
end

#should_autorotateObject



161
162
163
# File 'lib/ProMotion/screen/_screen_module.rb', line 161

def should_autorotate
  false
end

#should_rotate(orientation) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ProMotion/screen/_screen_module.rb', line 143

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_orientation?(orientation) ⇒ Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/ProMotion/screen/_screen_module.rb', line 168

def supported_orientation?(orientation)
  NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
end

#supported_orientationsObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ProMotion/screen/_screen_module.rb', line 172

def supported_orientations
  ors = 0
  NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
    case ori
    when "UIInterfaceOrientationPortrait"
      ors |= UIInterfaceOrientationMaskPortrait
    when "UIInterfaceOrientationLandscapeLeft"
      ors |= UIInterfaceOrientationMaskLandscapeLeft
    when "UIInterfaceOrientationLandscapeRight"
      ors |= UIInterfaceOrientationMaskLandscapeRight
    when "UIInterfaceOrientationPortraitUpsideDown"
      ors |= UIInterfaceOrientationMaskPortraitUpsideDown
    end
  end
  ors
end

#titleObject



124
125
126
# File 'lib/ProMotion/screen/_screen_module.rb', line 124

def title
  self.class.send(:get_title)
end

#title=(new_title) ⇒ Object



128
129
130
131
# File 'lib/ProMotion/screen/_screen_module.rb', line 128

def title=(new_title)
  self.class.title = new_title
  super
end

#view_controllerObject



138
139
140
141
# File 'lib/ProMotion/screen/_screen_module.rb', line 138

def view_controller
  warn "[DEPRECATION] `view_controller` is deprecated, as screens are now UIViewController subclasses."
  self
end

#view_controller=(vc) ⇒ Object

DEPRECATED


82
83
84
# File 'lib/ProMotion/screen/_screen_module.rb', line 82

def view_controller=(vc)
  set_view_controller(vc)
end

#view_did_appear(animated) ⇒ Object



107
108
109
110
# File 'lib/ProMotion/screen/_screen_module.rb', line 107

def view_did_appear(animated)
  # ProMotion::Screen.current_screen = self
  self.on_appear
end

#view_did_disappear(animated) ⇒ Object



118
119
120
121
# File 'lib/ProMotion/screen/_screen_module.rb', line 118

def view_did_disappear(animated)
  # ProMotion::Screen.current_screen = self.parent_screen if self.parent_screen
  self.on_disappear
end

#view_did_loadObject



96
# File 'lib/ProMotion/screen/_screen_module.rb', line 96

def view_did_load; end

#view_will_appear(animated) ⇒ Object



101
102
103
104
# File 'lib/ProMotion/screen/_screen_module.rb', line 101

def view_will_appear(animated)
  # ProMotion::Screen.current_screen = self
  self.will_appear
end

#view_will_disappear(animated) ⇒ Object



113
114
115
# File 'lib/ProMotion/screen/_screen_module.rb', line 113

def view_will_disappear(animated)
  self.will_disappear
end

#will_appearObject



105
# File 'lib/ProMotion/screen/_screen_module.rb', line 105

def will_appear; end

#will_disappearObject



116
# File 'lib/ProMotion/screen/_screen_module.rb', line 116

def will_disappear; end

#will_rotate(orientation, duration) ⇒ Object



158
159
# File 'lib/ProMotion/screen/_screen_module.rb', line 158

def will_rotate(orientation, duration)
end