ProMotion 1.2.1 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -10
  3. data/lib/ProMotion.rb +11 -2
  4. data/lib/ProMotion/cocoatouch/ns_string.rb +5 -0
  5. data/lib/ProMotion/cocoatouch/ns_url.rb +5 -0
  6. data/lib/ProMotion/cocoatouch/tab_bar_controller.rb +5 -7
  7. data/lib/ProMotion/cocoatouch/table_view_cell.rb +0 -16
  8. data/lib/ProMotion/cocoatouch/table_view_controller.rb +2 -3
  9. data/lib/ProMotion/cocoatouch/view_controller.rb +3 -6
  10. data/lib/ProMotion/delegate/delegate.rb +0 -3
  11. data/lib/ProMotion/delegate/delegate_module.rb +24 -20
  12. data/lib/ProMotion/{containers → ipad}/split_screen.rb +30 -32
  13. data/lib/ProMotion/{logger.rb → logger/logger.rb} +6 -5
  14. data/lib/ProMotion/screen/nav_bar_module.rb +126 -0
  15. data/lib/ProMotion/screen/screen.rb +0 -3
  16. data/lib/ProMotion/screen/screen_module.rb +54 -177
  17. data/lib/ProMotion/screen/screen_navigation.rb +29 -40
  18. data/lib/ProMotion/{view → styling}/styling.rb +17 -47
  19. data/lib/ProMotion/table/cell/table_view_cell_module.rb +76 -123
  20. data/lib/ProMotion/table/data/table_data.rb +1 -1
  21. data/lib/ProMotion/table/extensions/longpressable.rb +24 -0
  22. data/lib/ProMotion/table/extensions/refreshable.rb +1 -0
  23. data/lib/ProMotion/table/grouped_table_screen.rb +0 -5
  24. data/lib/ProMotion/table/table.rb +63 -83
  25. data/lib/ProMotion/table/table_screen.rb +0 -4
  26. data/lib/ProMotion/{containers → tabs}/tabs.rb +20 -21
  27. data/lib/ProMotion/version.rb +1 -1
  28. data/lib/ProMotion/web/web_screen.rb +0 -4
  29. data/lib/ProMotion/web/web_screen_module.rb +8 -5
  30. data/spec/functional/func_screen_spec.rb +14 -18
  31. data/spec/functional/func_split_screen_spec.rb +2 -2
  32. data/spec/functional/func_table_screen_spec.rb +54 -40
  33. data/spec/functional/func_web_screen_spec.rb +12 -17
  34. data/spec/helpers/test_helper.rb +27 -0
  35. data/spec/unit/delegate_spec.rb +4 -67
  36. data/spec/unit/image_title_screen.rb +9 -0
  37. data/spec/unit/image_view_title_screen.rb +9 -0
  38. data/spec/unit/load_view_spec.rb +27 -0
  39. data/spec/unit/main_spec.rb +0 -6
  40. data/spec/unit/screen_helpers_spec.rb +23 -17
  41. data/spec/unit/screen_spec.rb +21 -17
  42. data/spec/unit/searchable_table_spec.rb +55 -0
  43. data/spec/unit/split_screen_in_tab_bar_spec.rb +5 -5
  44. data/spec/unit/split_screen_spec.rb +4 -4
  45. data/spec/unit/tab_bar_spec.rb +79 -0
  46. data/spec/unit/tab_spec.rb +11 -5
  47. data/spec/unit/tables/table_module_spec.rb +22 -8
  48. data/spec/unit/tables/table_screen_spec.rb +1 -1
  49. data/spec/unit/tables/table_view_cell_spec.rb +16 -16
  50. data/spec/unit/view_helper_spec.rb +6 -81
  51. data/spec/unit/view_title_screen.rb +10 -0
  52. data/spec/unit/web_spec.rb +31 -37
  53. metadata +37 -111
  54. data/.gitignore +0 -33
  55. data/.travis.yml +0 -4
  56. data/CONTRIBUTING.md +0 -20
  57. data/Gemfile +0 -5
  58. data/LICENSE +0 -22
  59. data/ProMotion.gemspec +0 -30
  60. data/Rakefile +0 -66
  61. data/app/app_delegate.rb +0 -7
  62. data/app/screens/basic_screen.rb +0 -15
  63. data/lib/ProMotion/delegate/delegate_notifications.rb +0 -70
  64. data/lib/ProMotion/extensions/conversions.rb +0 -20
  65. data/lib/ProMotion/map/map_screen.rb +0 -10
  66. data/lib/ProMotion/map/map_screen_annotation.rb +0 -65
  67. data/lib/ProMotion/map/map_screen_module.rb +0 -212
  68. data/lib/ProMotion/push_notification/push_notification.rb +0 -58
  69. data/resources/WebScreen.html +0 -6
  70. data/resources/list.png +0 -0
  71. data/resources/test.png +0 -0
  72. data/spec/functional/func_image_title_screen.rb +0 -20
  73. data/spec/functional/func_image_view_title_screen.rb +0 -20
  74. data/spec/functional/func_map_screen_spec.rb +0 -162
  75. data/spec/functional/func_searchable_table_spec.rb +0 -56
  76. data/spec/functional/func_tab_bar_spec.rb +0 -78
  77. data/spec/functional/func_view_title_screen.rb +0 -21
  78. data/spec/helpers/basic_screen.rb +0 -3
  79. data/spec/helpers/custom_title_view.rb +0 -4
  80. data/spec/helpers/detail_screen.rb +0 -3
  81. data/spec/helpers/dummy_class.rb +0 -3
  82. data/spec/helpers/functional_screen.rb +0 -15
  83. data/spec/helpers/home_screen.rb +0 -19
  84. data/spec/helpers/image_title_screen.rb +0 -15
  85. data/spec/helpers/image_view_title_screen.rb +0 -15
  86. data/spec/helpers/map_screen.rb +0 -53
  87. data/spec/helpers/master_screen.rb +0 -3
  88. data/spec/helpers/present_screen.rb +0 -26
  89. data/spec/helpers/screen_module_view_controller.rb +0 -55
  90. data/spec/helpers/tab_screen.rb +0 -4
  91. data/spec/helpers/table_screen.rb +0 -117
  92. data/spec/helpers/table_screen_indexable.rb +0 -18
  93. data/spec/helpers/table_screen_refreshable.rb +0 -11
  94. data/spec/helpers/table_screen_searchable.rb +0 -72
  95. data/spec/helpers/test_delegate.rb +0 -34
  96. data/spec/helpers/test_delegate_colors.rb +0 -17
  97. data/spec/helpers/view_title_screen.rb +0 -15
  98. data/spec/helpers/web_screen.rb +0 -23
  99. data/spec/unit/map_spec.rb +0 -71
@@ -0,0 +1,126 @@
1
+ module ProMotion
2
+ module NavBarModule
3
+
4
+ def nav_bar?
5
+ !!self.navigationController
6
+ end
7
+
8
+ def navigation_controller
9
+ self.navigationController
10
+ end
11
+
12
+ def navigation_controller=(nav)
13
+ self.navigationController = nav
14
+ end
15
+
16
+ def navigationController=(nav)
17
+ @navigationController = nav
18
+ end
19
+
20
+ def set_nav_bar_button(side, args={})
21
+ button = create_toolbar_button(args)
22
+ button.setTintColor args[:tint_color] if args[:tint_color]
23
+
24
+ self.navigationItem.leftBarButtonItem = button if side == :left
25
+ self.navigationItem.rightBarButtonItem = button if side == :right
26
+ self.navigationItem.backBarButtonItem = button if side == :back
27
+
28
+ button
29
+ end
30
+
31
+ # TODO: In PM 2.1+, entirely remove this deprecated method.
32
+ def set_nav_bar_left_button(title, args={})
33
+ PM.logger.deprecated "set_nav_bar_right_button and set_nav_bar_left_button have been removed. Use set_nav_bar_button :right/:left instead."
34
+ end
35
+ alias_method :set_nav_bar_right_button, :set_nav_bar_left_button
36
+
37
+ def set_toolbar_items(buttons = [], animated = true)
38
+ self.toolbarItems = Array(buttons).map{|b| b.is_a?(UIBarButtonItem) ? b : create_toolbar_button(b) }
39
+ navigationController.setToolbarHidden(false, animated:animated)
40
+ end
41
+ alias_method :set_toolbar_buttons, :set_toolbar_items
42
+ alias_method :set_toolbar_button, :set_toolbar_items
43
+
44
+ def add_nav_bar(args = {})
45
+ self.navigationController ||= begin
46
+ self.first_screen = true if self.respond_to?(:first_screen=)
47
+ nav = NavigationController.alloc.initWithRootViewController(self)
48
+ nav.setModalTransitionStyle(args[:transition_style]) if args[:transition_style]
49
+ nav.setModalPresentationStyle(args[:presentation_style]) if args[:presentation_style]
50
+ nav
51
+ end
52
+ self.navigationController.toolbarHidden = !args[:toolbar] unless args[:toolbar].nil?
53
+ end
54
+
55
+ private
56
+
57
+ def create_toolbar_button(args = {})
58
+ button_type = args[:image] || args[:button] || args[:custom_view] || args[:title] || "Button"
59
+ bar_button_item button_type, args
60
+ end
61
+
62
+ def bar_button_item(button_type, args)
63
+ return PM.logger.deprecated("`system_icon:` no longer supported. Use `system_item:` instead.") if args[:system_icon]
64
+ return button_type if button_type.is_a?(UIBarButtonItem)
65
+ return bar_button_item_system_item(args) if args[:system_item]
66
+ return bar_button_item_image(button_type, args) if button_type.is_a?(UIImage)
67
+ return bar_button_item_string(button_type, args) if button_type.is_a?(String)
68
+ return bar_button_item_custom(button_type) if button_type.is_a?(UIView)
69
+ PM.logger.error("Please supply a title string, a UIImage or :system.") && nil
70
+ end
71
+
72
+ def bar_button_item_image(img, args)
73
+ UIBarButtonItem.alloc.initWithImage(img, style: map_bar_button_item_style(args[:style]), target: args[:target] || self, action: args[:action])
74
+ end
75
+
76
+ def bar_button_item_string(str, args)
77
+ UIBarButtonItem.alloc.initWithTitle(str, style: map_bar_button_item_style(args[:style]), target: args[:target] || self, action: args[:action])
78
+ end
79
+
80
+ def bar_button_item_system_item(args)
81
+ UIBarButtonItem.alloc.initWithBarButtonSystemItem(map_bar_button_system_item(args[:system_item]), target: args[:target] || self, action: args[:action])
82
+ end
83
+
84
+ def bar_button_item_custom(custom_view)
85
+ UIBarButtonItem.alloc.initWithCustomView(custom_view)
86
+ end
87
+
88
+ def map_bar_button_system_item(symbol)
89
+ {
90
+ done: UIBarButtonSystemItemDone,
91
+ cancel: UIBarButtonSystemItemCancel,
92
+ edit: UIBarButtonSystemItemEdit,
93
+ save: UIBarButtonSystemItemSave,
94
+ add: UIBarButtonSystemItemAdd,
95
+ flexible_space: UIBarButtonSystemItemFlexibleSpace,
96
+ fixed_space: UIBarButtonSystemItemFixedSpace,
97
+ compose: UIBarButtonSystemItemCompose,
98
+ reply: UIBarButtonSystemItemReply,
99
+ action: UIBarButtonSystemItemAction,
100
+ organize: UIBarButtonSystemItemOrganize,
101
+ bookmarks: UIBarButtonSystemItemBookmarks,
102
+ search: UIBarButtonSystemItemSearch,
103
+ refresh: UIBarButtonSystemItemRefresh,
104
+ stop: UIBarButtonSystemItemStop,
105
+ camera: UIBarButtonSystemItemCamera,
106
+ trash: UIBarButtonSystemItemTrash,
107
+ play: UIBarButtonSystemItemPlay,
108
+ pause: UIBarButtonSystemItemPause,
109
+ rewind: UIBarButtonSystemItemRewind,
110
+ fast_forward: UIBarButtonSystemItemFastForward,
111
+ undo: UIBarButtonSystemItemUndo,
112
+ redo: UIBarButtonSystemItemRedo,
113
+ page_curl: UIBarButtonSystemItemPageCurl
114
+ }[symbol] || UIBarButtonSystemItemDone
115
+ end
116
+
117
+ def map_bar_button_item_style(symbol)
118
+ {
119
+ plain: UIBarButtonItemStylePlain,
120
+ bordered: UIBarButtonItemStyleBordered,
121
+ done: UIBarButtonItemStyleDone
122
+ }[symbol] || UIBarButtonItemStyleDone
123
+ end
124
+
125
+ end
126
+ end
@@ -1,6 +1,3 @@
1
- motion_require '../cocoatouch/view_controller'
2
- motion_require 'screen_module'
3
-
4
1
  module ProMotion
5
2
  class Screen < ViewController
6
3
  # You can inherit a screen from any UIViewController if you include the ScreenModule
@@ -1,141 +1,35 @@
1
- motion_require 'screen_navigation'
2
- motion_require '../view/styling'
3
- motion_require '../containers/tabs'
4
- motion_require '../containers/split_screen'
5
-
6
1
  module ProMotion
7
2
  module ScreenModule
8
3
  include ProMotion::ScreenNavigation
9
4
  include ProMotion::Styling
5
+ include ProMotion::NavBarModule
10
6
  include ProMotion::Tabs
11
- include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2")
7
+ include ProMotion::SplitScreen if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
12
8
 
13
9
  attr_accessor :parent_screen, :first_screen, :modal, :split_screen
14
10
 
15
- def on_create(args = {})
16
- unless self.is_a?(UIViewController)
17
- raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
18
- end
19
-
11
+ def screen_init(args = {})
12
+ check_ancestry
20
13
  resolve_title
21
-
22
- self.tab_bar_item = self.class.send(:get_tab_bar_item)
23
- self.refresh_tab_bar_item if self.tab_bar_item
24
- self.class.send(:get_title)
25
-
26
- args.each { |k, v| self.send("#{k}=", v) if self.respond_to?("#{k}=") }
27
-
28
- self.add_nav_bar(args) if args[:nav_bar]
29
- self.navigationController.toolbarHidden = !args[:toolbar] unless args[:toolbar].nil?
30
- self.screen_setup
31
- self.on_init if self.respond_to?(:on_init)
32
- self
33
- end
34
-
35
- def screen_setup
14
+ tab_bar_setup
15
+ set_attributes self, args
16
+ add_nav_bar(args) if args[:nav_bar]
17
+ try :screen_setup
18
+ try :on_init
19
+ PM.logger.deprecated "In #{self.class.to_s}, #on_create has been deprecated and removed. Use #screen_init instead." if respond_to?(:on_create)
36
20
  end
37
21
 
38
22
  def modal?
39
23
  self.modal == true
40
24
  end
41
25
 
42
- def nav_bar?
43
- !!self.navigationController
44
- end
45
-
46
- def navigation_controller
47
- self.navigationController
48
- end
49
-
50
- def navigation_controller=(nav)
51
- @navigationController = nav
52
- end
53
-
54
- def navigationController=(nav)
55
- @navigationController = nav
56
- end
57
-
58
26
  def resolve_title
59
- if self.class.send(:get_title).kind_of? String
60
- self.title = self.class.send(:get_title)
61
- elsif self.class.send(:get_title).kind_of? UIView
62
- self.navigationItem.titleView = self.class.send(:get_title)
63
- elsif self.class.send(:get_title).kind_of? UIImage
64
- self.navigationItem.titleView = UIImageView.alloc.initWithImage(self.class.send(:get_title))
65
- else
66
- PM.logger.warn("title expects string, UIView, or UIImage, but #{self.class.send(:get_title).class.to_s} given.")
67
- end
68
- end
69
-
70
- def add_nav_bar(args = {})
71
- self.navigationController ||= begin
72
- self.first_screen = true if self.respond_to?(:first_screen=)
73
- nav = NavigationController.alloc.initWithRootViewController(self)
74
- nav.setModalTransitionStyle(args[:transition_style]) if args[:transition_style]
75
- nav.setModalPresentationStyle(args[:presentation_style]) if args[:presentation_style]
76
- nav
77
- end
78
- end
79
-
80
- def set_nav_bar_right_button(title, args={})
81
- args[:title] = title
82
- set_nav_bar_button :right, args
83
- end
84
-
85
- def set_nav_bar_left_button(title, args={})
86
- args[:title] = title
87
- set_nav_bar_button :left, args
88
- end
89
-
90
- def set_nav_bar_button(side, args={})
91
- button = create_toolbar_button(args)
92
-
93
- self.navigationItem.leftBarButtonItem = button if side == :left
94
- self.navigationItem.rightBarButtonItem = button if side == :right
95
- self.navigationItem.backBarButtonItem = button if side == :back
96
-
97
- button
98
- end
99
-
100
- def create_toolbar_button(args = {})
101
- args[:style] = map_bar_button_item_style(args[:style])
102
- args[:target] ||= self
103
- args[:action] ||= nil
104
- args[:custom_view] = args[:custom_view] if args[:custom_view]
105
- args[:system_item] ||= args[:system_icon] # backwards compatibility
106
- args[:system_item] = map_bar_button_system_item(args[:system_item]) if args[:system_item] && args[:system_item].is_a?(Symbol)
107
-
108
- button_type = args[:image] || args[:button] || args[:system_item] || args[:custom_view] || args[:title] || "Button"
109
-
110
- bar_button_item button_type, args
111
- end
112
-
113
- def set_toolbar_items(buttons = [], animated = true)
114
- buttons = Array(buttons)
115
- self.toolbarItems = buttons.map{|b| b.is_a?(UIBarButtonItem) ? b : create_toolbar_button(b) }
116
- navigation_controller.setToolbarHidden(false, animated:animated)
117
- end
118
- alias_method :set_toolbar_buttons, :set_toolbar_items
119
- alias_method :set_toolbar_button, :set_toolbar_items
120
-
121
- # TODO: Make this better. Not able to do image: "logo", for example.
122
- def bar_button_item(button_type, args)
123
- case button_type
124
- when UIBarButtonItem
125
- button_type
126
- when UIImage
127
- UIBarButtonItem.alloc.initWithImage(button_type, style: args[:style], target: args[:target], action: args[:action])
128
- when String
129
- UIBarButtonItem.alloc.initWithTitle(button_type, style: args[:style], target: args[:target], action: args[:action])
27
+ case self.class.title_type
28
+ when :text then self.title = self.class.title
29
+ when :view then self.navigationItem.titleView = self.class.title
30
+ when :image then self.navigationItem.titleView = UIImageView.alloc.initWithImage(UIImage.imageNamed(self.class.title))
130
31
  else
131
- if args[:custom_view]
132
- UIBarButtonItem.alloc.initWithCustomView(args[:custom_view])
133
- elsif args[:system_item]
134
- UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_item], target: args[:target], action: args[:action])
135
- else
136
- PM.logger.error("Please supply a title string, a UIImage or :system.")
137
- nil
138
- end
32
+ PM.logger.warn("title expects string, UIView, or UIImage, but #{self.class.title.class.to_s} given.")
139
33
  end
140
34
  end
141
35
 
@@ -147,7 +41,9 @@ module ProMotion
147
41
  self.first_screen == true
148
42
  end
149
43
 
150
- def view_did_load; end
44
+ def view_did_load
45
+ self.send(:on_load) if self.respond_to?(:on_load)
46
+ end
151
47
 
152
48
  def view_will_appear(animated)
153
49
  self.will_appear
@@ -206,10 +102,6 @@ module ProMotion
206
102
  def on_rotate
207
103
  end
208
104
 
209
- def supported_orientation?(orientation)
210
- NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
211
- end
212
-
213
105
  def supported_orientations
214
106
  orientations = 0
215
107
  NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
@@ -227,15 +119,16 @@ module ProMotion
227
119
  orientations
228
120
  end
229
121
 
122
+ def supported_orientation?(orientation)
123
+ NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
124
+ end
125
+
230
126
  def supported_device_families
231
127
  NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].map do |m|
232
- # TODO: What about universal apps?
233
- case m
234
- when "1"
235
- :iphone
236
- when "2"
237
- :ipad
238
- end
128
+ {
129
+ "1" => :iphone,
130
+ "2" => :ipad
131
+ }[m] || :unknown_device
239
132
  end
240
133
  end
241
134
 
@@ -251,63 +144,47 @@ module ProMotion
251
144
  return self.view_or_self.frame
252
145
  end
253
146
 
254
- def map_bar_button_item_style(symbol)
255
- symbol = {
256
- plain: UIBarButtonItemStylePlain,
257
- bordered: UIBarButtonItemStyleBordered,
258
- done: UIBarButtonItemStyleDone
259
- }[symbol] if symbol.is_a?(Symbol)
260
- symbol || UIBarButtonItemStyleBordered
147
+ private
148
+
149
+ def tab_bar_setup
150
+ self.tab_bar_item = self.class.send(:get_tab_bar_item)
151
+ self.refresh_tab_bar_item if self.tab_bar_item
152
+ end
153
+
154
+ def check_ancestry
155
+ unless self.is_a?(UIViewController)
156
+ raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
157
+ end
261
158
  end
262
159
 
263
- def map_bar_button_system_item(symbol)
264
- {
265
- done: UIBarButtonSystemItemDone,
266
- cancel: UIBarButtonSystemItemCancel,
267
- edit: UIBarButtonSystemItemEdit,
268
- save: UIBarButtonSystemItemSave,
269
- add: UIBarButtonSystemItemAdd,
270
- flexible_space: UIBarButtonSystemItemFlexibleSpace,
271
- fixed_space: UIBarButtonSystemItemFixedSpace,
272
- compose: UIBarButtonSystemItemCompose,
273
- reply: UIBarButtonSystemItemReply,
274
- action: UIBarButtonSystemItemAction,
275
- organize: UIBarButtonSystemItemOrganize,
276
- bookmarks: UIBarButtonSystemItemBookmarks,
277
- search: UIBarButtonSystemItemSearch,
278
- refresh: UIBarButtonSystemItemRefresh,
279
- stop: UIBarButtonSystemItemStop,
280
- camera: UIBarButtonSystemItemCamera,
281
- trash: UIBarButtonSystemItemTrash,
282
- play: UIBarButtonSystemItemPlay,
283
- pause: UIBarButtonSystemItemPause,
284
- rewind: UIBarButtonSystemItemRewind,
285
- fast_forward: UIBarButtonSystemItemFastForward,
286
- undo: UIBarButtonSystemItemUndo,
287
- redo: UIBarButtonSystemItemRedo,
288
- page_curl: UIBarButtonSystemItemPageCurl
289
- }[symbol] || UIBarButtonSystemItemDone
160
+ def try(method, *args)
161
+ send(method, *args) if respond_to?(method)
290
162
  end
291
163
 
292
164
  # Class methods
293
165
  module ClassMethods
294
- def debug_mode
295
- @debug_mode
166
+ def title(t=nil)
167
+ if t && t.is_a?(String) == false
168
+ PM.logger.deprecated "You're trying to set the title of #{self.to_s} to an instance of #{t.class.to_s}. In ProMotion 2+, you must use `title_image` or `title_view` instead."
169
+ return raise StandardError
170
+ end
171
+ @title = t if t
172
+ @title_type = :text if t
173
+ @title ||= self.to_s
296
174
  end
297
175
 
298
- def debug_mode=(v)
299
- @debug_mode = v
176
+ def title_type
177
+ @title_type || :text
300
178
  end
301
179
 
302
- def title(t)
180
+ def title_image(t)
303
181
  @title = t
182
+ @title_type = :image
304
183
  end
305
- def title=(t)
184
+
185
+ def title_view(t)
306
186
  @title = t
307
- end
308
-
309
- def get_title
310
- @title ||= self.to_s
187
+ @title_type = :view
311
188
  end
312
189
  end
313
190
 
@@ -2,39 +2,28 @@ module ProMotion
2
2
  module ScreenNavigation
3
3
 
4
4
  def open_screen(screen, args = {})
5
- args = { in_detail: false, in_master: false, close_all: false, modal: false, in_tab: false, animated: true }.merge args
5
+ args = { animated: true }.merge(args)
6
6
 
7
7
  # Apply properties to instance
8
8
  screen = set_up_screen_for_open(screen, args)
9
9
  ensure_wrapper_controller_in_place(screen, args)
10
10
 
11
- if args[:in_detail] && self.split_screen
12
- self.split_screen.detail_screen = screen
13
-
14
- elsif args[:in_master] && self.split_screen
15
- self.split_screen.master_screen = screen
16
-
17
- elsif args[:close_all]
18
- open_root_screen screen
19
-
20
- elsif args[:modal]
21
- present_modal_view_controller screen, args[:animated], args[:completion]
22
-
23
- elsif args[:in_tab] && self.tab_bar
24
- present_view_controller_in_tab_bar_controller screen, args[:in_tab]
25
-
26
- elsif self.navigationController
27
- push_view_controller screen, self.navigationController, args[:animated].nil? ? true : args[:animated]
28
-
29
- else
30
- open_root_screen (screen.navigationController || screen)
31
-
32
- end
33
-
11
+ opened ||= open_in_split_screen(screen, args) if self.split_screen
12
+ opened ||= open_root_screen(screen) if args[:close_all]
13
+ opened ||= present_modal_view_controller(screen, args) if args[:modal]
14
+ opened ||= open_in_tab(screen, args[:in_tab]) if args[:in_tab]
15
+ opened ||= push_view_controller(screen, self.navigationController, !!args[:animated]) if self.navigationController
16
+ opened ||= open_root_screen(screen.navigationController || screen)
34
17
  screen
35
18
  end
36
19
  alias :open :open_screen
37
20
 
21
+ def open_in_split_screen(screen, args)
22
+ self.split_screen.detail_screen = screen if args[:in_detail]
23
+ self.split_screen.master_screen = screen if args[:in_master]
24
+ args[:in_detail] || args[:in_master]
25
+ end
26
+
38
27
  def open_root_screen(screen)
39
28
  app_delegate.open_root_screen(screen)
40
29
  end
@@ -81,11 +70,12 @@ module ProMotion
81
70
  PM.logger.error "You need a nav_bar if you are going to push #{vc.to_s} onto it."
82
71
  end
83
72
  nav_controller ||= self.navigationController
73
+ return if nav_controller.topViewController == vc
84
74
  vc.first_screen = false if vc.respond_to?(:first_screen=)
85
75
  nav_controller.pushViewController(vc, animated: animated)
86
76
  end
87
77
 
88
- protected
78
+ protected
89
79
 
90
80
  def set_up_screen_for_open(screen, args={})
91
81
 
@@ -117,24 +107,23 @@ module ProMotion
117
107
  end
118
108
  end
119
109
 
120
- def present_modal_view_controller(screen, animated, completion)
121
- self.presentViewController((screen.navigationController || screen), animated:animated, completion:completion)
110
+ def present_modal_view_controller(screen, args={})
111
+ self.presentViewController((screen.navigationController || screen), animated: args[:animated], completion: args[:completion])
122
112
  end
123
113
 
124
- def present_view_controller_in_tab_bar_controller(screen, tab_name)
125
- vc = open_tab tab_name
126
- if vc
127
-
128
- if vc.is_a?(UINavigationController)
129
- push_view_controller(screen, vc)
130
- else
131
- # TODO: This should probably open the vc, shouldn't it?
132
- # This isn't well tested and needs to work better.
133
- self.tab_bar.selectedIndex = vc.tabBarItem.tag
134
- end
135
-
114
+ def open_in_tab(screen, tab_name)
115
+ vc = open_tab(tab_name)
116
+ return PM.logger.error("No tab bar item '#{tab_name}'") && nil unless vc
117
+ if vc.is_a?(UINavigationController)
118
+ push_view_controller(screen, vc)
136
119
  else
137
- PM.logger.error "No tab bar item '#{tab_name}'"
120
+ replace_view_controller(screen, vc)
121
+ end
122
+ end
123
+
124
+ def replace_view_controller(new_vc, old_vc)
125
+ self.tab_bar.viewControllers = self.tab_bar.viewControllers.map do |vc|
126
+ vc == old_vc ? new_vc : vc
138
127
  end
139
128
  end
140
129