ProMotion 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/.gitignore +0 -1
  2. data/Gemfile +1 -1
  3. data/README.md +336 -92
  4. data/Rakefile +1 -1
  5. data/lib/ProMotion.rb +14 -0
  6. data/lib/ProMotion/app_delegate.rb +63 -0
  7. data/lib/ProMotion/cocoatouch/NavigationController.rb +4 -0
  8. data/lib/ProMotion/cocoatouch/TableViewCell.rb +16 -0
  9. data/lib/ProMotion/cocoatouch/TableViewController.rb +50 -0
  10. data/lib/ProMotion/cocoatouch/ViewController.rb +52 -0
  11. data/lib/ProMotion/helpers/console.rb +24 -0
  12. data/lib/ProMotion/helpers/measure_helper.rb +20 -0
  13. data/lib/ProMotion/helpers/system_helper.rb +29 -0
  14. data/lib/ProMotion/helpers/tab_bar.rb +115 -0
  15. data/lib/ProMotion/helpers/view_helper.rb +39 -0
  16. data/lib/ProMotion/pro_motion.rb +3 -0
  17. data/lib/ProMotion/screen_helpers/_tables/_searchable_table.rb +66 -0
  18. data/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +265 -0
  19. data/lib/ProMotion/screen_helpers/_tables/grouped_table.rb +13 -0
  20. data/lib/ProMotion/screen_helpers/_tables/plain_table.rb +14 -0
  21. data/lib/ProMotion/screen_helpers/screen_elements.rb +43 -0
  22. data/lib/ProMotion/screen_helpers/screen_navigation.rb +106 -0
  23. data/lib/ProMotion/screen_helpers/screen_tabs.rb +92 -0
  24. data/lib/ProMotion/screens/_screen_module.rb +222 -0
  25. data/lib/ProMotion/screens/_table_screen_module.rb +30 -0
  26. data/lib/ProMotion/screens/screen.rb +7 -0
  27. data/lib/ProMotion/screens/table_screen.rb +15 -0
  28. data/lib/ProMotion/version.rb +3 -0
  29. metadata +43 -63
  30. data/app/app_delegate.rb +0 -5
  31. data/app/screens/home_screen.rb +0 -21
  32. data/app/screens/test_screen.rb +0 -26
@@ -0,0 +1,92 @@
1
+ module ProMotion
2
+ module ScreenTabs
3
+ def tab_bar_controller(*screens)
4
+ tab_bar_controller = UITabBarController.alloc.init
5
+
6
+ view_controllers = []
7
+ tag_index = 0
8
+
9
+ screens.map! { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes
10
+
11
+ screens.each do |s|
12
+ if s.is_a?(ProMotion::Screen) || s.is_a?(ProMotion::TableScreen) || s.is_a?(ProMotion::ScreenModule)
13
+ s = s.new if s.respond_to?(:new)
14
+ s.tabBarItem.tag = tag_index
15
+ s.parent_screen = self if self.is_a?(UIViewController) && s.respond_to?("parent_screen=")
16
+ s.tab_bar = tab_bar_controller if s.respond_to?("tab_bar=")
17
+ view_controllers << s.main_controller
18
+ tag_index += 1
19
+ else
20
+ Console.log("Non-Screen passed into tab_bar_controller: #{s.to_s}", withColor: Console::RED_COLOR)
21
+ end
22
+
23
+ s.on_load if s.respond_to?(:on_load)
24
+ end
25
+
26
+ tab_bar_controller.viewControllers = view_controllers
27
+ tab_bar_controller
28
+ end
29
+
30
+ # Open a UITabBarController with the specified screens as the
31
+ # root view controller of the current app.
32
+ # @param [Array] A comma-delimited list of screen classes or instances.
33
+ # @return [UITabBarController]
34
+ def open_tab_bar(*screens)
35
+ tab_bar = tab_bar_controller(*screens)
36
+ UIApplication.sharedApplication.delegate.load_root_screen(tab_bar)
37
+ tab_bar
38
+ end
39
+
40
+ def open_tab(tab)
41
+ if tab.is_a? String
42
+ return self.select(self.tab_bar, title: tab)
43
+ elsif tab.is_a? Numeric
44
+ tab_bar_controller.selectedIndex = tab
45
+ return tab_bar_controller.viewControllers[tab]
46
+ else
47
+ $stderr.puts "Unable to open tab #{tab.to_s} because it isn't a string."
48
+ end
49
+ end
50
+
51
+ def create_tab_bar_icon(icon, tag)
52
+ return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
53
+ end
54
+
55
+ def create_tab_bar_icon_custom(title, image_name, tag)
56
+ icon_image = UIImage.imageNamed(image_name)
57
+ return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag)
58
+ end
59
+
60
+ def create_tab_bar_item(tab={})
61
+ title = "Untitled"
62
+ title = tab[:title] if tab[:title]
63
+ tab[:tag] ||= @current_tag ||= 0
64
+ @current_tag = tab[:tag] + 1
65
+
66
+ tab_bar_item = create_tab_bar_icon(tab[:system_icon], tab[:tag]) if tab[:system_icon]
67
+ tab_bar_item = create_tab_bar_icon_custom(title, tab[:icon], tab[:tag]) if tab[:icon]
68
+
69
+ tab_bar_item.badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0
70
+
71
+ return tab_bar_item
72
+ end
73
+
74
+ def select(tab_bar_controller, title: title)
75
+ root_controller = nil
76
+ tab_bar_controller.viewControllers.each do |vc|
77
+ if vc.tabBarItem.title == title
78
+ tab_bar_controller.selectedViewController = vc
79
+ root_controller = vc
80
+ break
81
+ end
82
+ end
83
+ root_controller
84
+ end
85
+
86
+ def replace_current_item(tab_bar_controller, view_controller: vc)
87
+ controllers = NSMutableArray.arrayWithArray(tab_bar_controller.viewControllers)
88
+ controllers.replaceObjectAtIndex(tab_bar_controller.selectedIndex, withObject: vc)
89
+ tab_bar_controller.viewControllers = controllers
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,222 @@
1
+ module ProMotion
2
+ module ScreenModule
3
+ include ProMotion::ScreenNavigation
4
+ include ProMotion::ScreenElements
5
+ include ProMotion::SystemHelper
6
+ include ProMotion::ScreenTabs
7
+
8
+ attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
9
+
10
+ def on_create(args = {})
11
+ unless self.is_a?(UIViewController)
12
+ raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
13
+ end
14
+
15
+ args.each do |k, v|
16
+ self.send("#{k}=", v) if self.respond_to?("#{k}=")
17
+ end
18
+
19
+ self.add_nav_bar if args[:nav_bar]
20
+ self.table_setup if self.respond_to?(:table_setup)
21
+ self.on_init if self.respond_to?(:on_init)
22
+ self
23
+ end
24
+
25
+ def is_modal?
26
+ self.modal == true
27
+ end
28
+
29
+ def has_nav_bar?
30
+ self.navigation_controller.nil? != true
31
+ end
32
+
33
+ def navigation_controller
34
+ @navigation_controller ||= self.navigationController
35
+ end
36
+
37
+ def navigation_controller=(val)
38
+ @navigation_controller = val
39
+ val
40
+ end
41
+
42
+ # [DEPRECATED]
43
+ def load_view_controller
44
+ warn "[DEPRECATION] `load_view_controller` is deprecated and doesn't actually do anything anymore. You can safely remove it from your code."
45
+ end
46
+
47
+ def set_tab_bar_item(args = {})
48
+ self.tab_bar_item = args
49
+ refresh_tab_bar_item
50
+ end
51
+
52
+ def refresh_tab_bar_item
53
+ self.tabBarItem = create_tab_bar_item(self.tab_bar_item) if self.tab_bar_item
54
+ end
55
+
56
+ def add_nav_bar
57
+ self.navigation_controller = NavigationController.alloc.initWithRootViewController(self)
58
+ self.first_screen = true
59
+ end
60
+
61
+ def set_nav_bar_right_button(title, args={})
62
+ args[:style] ||= UIBarButtonItemStyleBordered
63
+ args[:target] ||= self
64
+ args[:action] ||= nil
65
+
66
+ right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
67
+ self.navigationItem.rightBarButtonItem = right_button
68
+ right_button
69
+ end
70
+
71
+ def set_nav_bar_left_button(title, args={})
72
+ args[:style] ||= UIBarButtonItemStyleBordered
73
+ args[:target] ||= self
74
+ args[:action] ||= nil
75
+
76
+ left_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
77
+ self.navigationItem.leftBarButtonItem = left_button
78
+ left_button
79
+ end
80
+
81
+ # [DEPRECATED]
82
+ def view_controller=(vc)
83
+ set_view_controller(vc)
84
+ end
85
+
86
+ def first_screen?
87
+ self.first_screen == true
88
+ end
89
+
90
+ # [DEPRECATED]
91
+ def set_view_controller(vc)
92
+ warn "[DEPRECATION] `set_view_controller` is deprecated and discontinued. Please inherit from the UIViewController you wish to use and include ProMotion::ScreenViewController instead."
93
+ self
94
+ end
95
+
96
+ def view_did_load; end
97
+ def on_opened
98
+ warn "[DEPRECATION] `on_opened` is deprecated. Please use `on_appear` instead."
99
+ end
100
+
101
+ def view_will_appear(animated)
102
+ # ProMotion::Screen.current_screen = self
103
+ self.will_appear
104
+ end
105
+ def will_appear; end
106
+
107
+ def view_did_appear(animated)
108
+ # ProMotion::Screen.current_screen = self
109
+ self.on_appear
110
+ end
111
+ def on_appear; end
112
+
113
+ def view_will_disappear(animated)
114
+ self.will_disappear
115
+ end
116
+ def will_disappear; end
117
+
118
+ def view_did_disappear(animated)
119
+ # ProMotion::Screen.current_screen = self.parent_screen if self.parent_screen
120
+ self.on_disappear
121
+ end
122
+ def on_disappear; end
123
+
124
+ def title
125
+ self.class.send(:get_title)
126
+ end
127
+
128
+ def title=(new_title)
129
+ self.class.title = new_title
130
+ super
131
+ end
132
+
133
+ def main_controller
134
+ return self.navigationController if self.navigationController
135
+ self
136
+ end
137
+
138
+ def view_controller
139
+ warn "[DEPRECATION] `view_controller` is deprecated, as screens are now UIViewController subclasses."
140
+ self
141
+ end
142
+
143
+ def should_rotate(orientation)
144
+ case orientation
145
+ when UIInterfaceOrientationPortrait
146
+ return supported_orientation?("UIInterfaceOrientationPortrait")
147
+ when UIInterfaceOrientationLandscapeLeft
148
+ return supported_orientation?("UIInterfaceOrientationLandscapeLeft")
149
+ when UIInterfaceOrientationLandscapeRight
150
+ return supported_orientation?("UIInterfaceOrientationLandscapeRight")
151
+ when UIInterfaceOrientationPortraitUpsideDown
152
+ return supported_orientation?("UIInterfaceOrientationPortraitUpsideDown")
153
+ else
154
+ false
155
+ end
156
+ end
157
+
158
+ def will_rotate(orientation, duration)
159
+ end
160
+
161
+ def should_autorotate
162
+ true
163
+ end
164
+
165
+ def on_rotate
166
+ end
167
+
168
+ def supported_orientation?(orientation)
169
+ NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
170
+ end
171
+
172
+ def supported_orientations
173
+ ors = 0
174
+ NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
175
+ case ori
176
+ when "UIInterfaceOrientationPortrait"
177
+ ors |= UIInterfaceOrientationMaskPortrait
178
+ when "UIInterfaceOrientationLandscapeLeft"
179
+ ors |= UIInterfaceOrientationMaskLandscapeLeft
180
+ when "UIInterfaceOrientationLandscapeRight"
181
+ ors |= UIInterfaceOrientationMaskLandscapeRight
182
+ when "UIInterfaceOrientationPortraitUpsideDown"
183
+ ors |= UIInterfaceOrientationMaskPortraitUpsideDown
184
+ end
185
+ end
186
+ ors
187
+ end
188
+
189
+ # Class methods
190
+ module ClassMethods
191
+ def debug_mode
192
+ @debug_mode
193
+ end
194
+
195
+ def debug_mode=(v)
196
+ @debug_mode = v
197
+ end
198
+
199
+ def current_screen=(s)
200
+ @current_screen = s
201
+ end
202
+
203
+ def current_screen
204
+ @current_screen
205
+ end
206
+
207
+ def title(t)
208
+ @title = t
209
+ end
210
+ def title=(t)
211
+ @title = t
212
+ end
213
+ def get_title
214
+ @title ||= self.to_s
215
+ end
216
+ end
217
+
218
+ def self.included(base)
219
+ base.extend(ClassMethods)
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,30 @@
1
+ module ProMotion
2
+ module TableScreenModule
3
+ include MotionTable::PlainTable
4
+ include MotionTable::SearchableTable
5
+ include ProMotion::ScreenModule
6
+
7
+ def update_table_data
8
+ self.update_table_view_data(table_data)
9
+ end
10
+
11
+ module TableClassMethods
12
+ def searchable(params={})
13
+ @searchable_params = params
14
+ @searchable = true
15
+ end
16
+
17
+ def get_searchable_params
18
+ @searchable_params ||= nil
19
+ end
20
+
21
+ def get_searchable
22
+ @searchable ||= false
23
+ end
24
+ end
25
+ def self.included(base)
26
+ base.extend(ClassMethods)
27
+ base.extend(TableClassMethods)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ module ProMotion
2
+ class Screen < ViewController
3
+ # You can inherit a screen from any UIViewController if you include the ScreenModule
4
+ # Just make sure to implement the Obj-C methods in cocoatouch/ViewController.rb.
5
+ include ProMotion::ScreenModule
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module ProMotion
2
+ # You can inherit a table screen from any UITableViewController if you include TableScreenModule
3
+ # Just make sure to implement the Obj-C methods in cocoatouch/TableViewController.rb.
4
+ class TableScreen < TableViewController
5
+ include ProMotion::TableScreenModule
6
+ end
7
+
8
+ class GroupedTableScreen < TableScreen
9
+ include ProMotion::MotionTable::GroupedTable
10
+ end
11
+
12
+ class SectionedTableScreen < TableScreen
13
+ include ProMotion::MotionTable::SectionedTable
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module ProMotion
2
+ VERSION = "0.5.0" unless defined?(ProMotion::VERSION)
3
+ end
metadata CHANGED
@@ -1,37 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ProMotion
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jamon Holmgren
14
9
  - Silas Matson
15
10
  - ClearSight Studio
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2013-02-21 00:00:00 Z
14
+ date: 2013-03-04 00:00:00.000000000 Z
21
15
  dependencies: []
22
-
23
16
  description: ProMotion is a new way to easily build RubyMotion iOS apps.
24
- email:
17
+ email:
25
18
  - jamon@clearsightstudio.com
26
19
  - silas@clearsightstudio.com
27
20
  - contact@clearsightstudio.com
28
21
  executables: []
29
-
30
22
  extensions: []
31
-
32
23
  extra_rdoc_files: []
33
-
34
- files:
24
+ files:
35
25
  - .gitignore
36
26
  - .repl_history
37
27
  - Gemfile
@@ -40,66 +30,56 @@ files:
40
30
  - ProMotion.gemspec
41
31
  - README.md
42
32
  - Rakefile
43
- - app/app_delegate.rb
44
- - app/screens/home_screen.rb
45
- - app/screens/test_screen.rb
46
33
  - lib/ProMotion.rb
47
34
  - lib/ProMotion/.DS_Store
48
- - lib/ProMotion/_cocoatouch/NavigationController.rb
49
- - lib/ProMotion/_cocoatouch/TableViewCell.rb
50
- - lib/ProMotion/_cocoatouch/TableViewController.rb
51
- - lib/ProMotion/_cocoatouch/ViewController.rb
52
- - lib/ProMotion/_helpers/console.rb
53
- - lib/ProMotion/_helpers/measure_helper.rb
54
- - lib/ProMotion/_helpers/motion-table/1st/searchable_table.rb
55
- - lib/ProMotion/_helpers/motion-table/1st/sectioned_table.rb
56
- - lib/ProMotion/_helpers/motion-table/2nd/grouped_table.rb
57
- - lib/ProMotion/_helpers/motion-table/2nd/plain_table.rb
58
- - lib/ProMotion/_helpers/system_helper.rb
59
- - lib/ProMotion/_helpers/tab_bar.rb
60
- - lib/ProMotion/_helpers/view_helper.rb
61
- - lib/ProMotion/_screen_modules/screen_elements.rb
62
- - lib/ProMotion/_screen_modules/screen_navigation.rb
63
- - lib/ProMotion/_screen_modules/screen_tabs.rb
64
35
  - lib/ProMotion/app_delegate.rb
36
+ - lib/ProMotion/cocoatouch/NavigationController.rb
37
+ - lib/ProMotion/cocoatouch/TableViewCell.rb
38
+ - lib/ProMotion/cocoatouch/TableViewController.rb
39
+ - lib/ProMotion/cocoatouch/ViewController.rb
40
+ - lib/ProMotion/helpers/console.rb
41
+ - lib/ProMotion/helpers/measure_helper.rb
42
+ - lib/ProMotion/helpers/system_helper.rb
43
+ - lib/ProMotion/helpers/tab_bar.rb
44
+ - lib/ProMotion/helpers/view_helper.rb
65
45
  - lib/ProMotion/pro_motion.rb
66
- - lib/ProMotion/screen/_screen_module.rb
67
- - lib/ProMotion/screen/_table_screen_module.rb
68
- - lib/ProMotion/screen/screen.rb
69
- - lib/ProMotion/screen/table_screen.rb
46
+ - lib/ProMotion/screen_helpers/_tables/_searchable_table.rb
47
+ - lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb
48
+ - lib/ProMotion/screen_helpers/_tables/grouped_table.rb
49
+ - lib/ProMotion/screen_helpers/_tables/plain_table.rb
50
+ - lib/ProMotion/screen_helpers/screen_elements.rb
51
+ - lib/ProMotion/screen_helpers/screen_navigation.rb
52
+ - lib/ProMotion/screen_helpers/screen_tabs.rb
53
+ - lib/ProMotion/screens/_screen_module.rb
54
+ - lib/ProMotion/screens/_table_screen_module.rb
55
+ - lib/ProMotion/screens/screen.rb
56
+ - lib/ProMotion/screens/table_screen.rb
70
57
  - lib/ProMotion/version.rb
71
58
  homepage: https://github.com/clearsightstudio/ProMotion
72
59
  licenses: []
73
-
74
60
  post_install_message:
75
61
  rdoc_options: []
76
-
77
- require_paths:
62
+ require_paths:
78
63
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
80
65
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
71
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- version: "0"
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
97
76
  requirements: []
98
-
99
77
  rubyforge_project:
100
- rubygems_version: 1.8.24
78
+ rubygems_version: 1.8.25
101
79
  signing_key:
102
80
  specification_version: 3
103
- summary: ProMotion is a new way to organize RubyMotion apps. Instead of dealing with UIViewControllers, you work with Screens. Screens are a logical way to think of your app and include a ton of great utilities to make iOS development more like Ruby and less like Objective-C.
81
+ summary: ProMotion is a new way to organize RubyMotion apps. Instead of dealing with
82
+ UIViewControllers, you work with Screens. Screens are a logical way to think of
83
+ your app and include a ton of great utilities to make iOS development more like
84
+ Ruby and less like Objective-C.
104
85
  test_files: []
105
-