ProMotion 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.gitignore +14 -22
  2. data/.repl_history +0 -0
  3. data/Gemfile.lock +14 -0
  4. data/ProMotion.gemspec +4 -3
  5. data/README.md +252 -25
  6. data/Rakefile +5 -3
  7. data/app/app_delegate.rb +2 -2
  8. data/app/screens/home_screen.rb +14 -3
  9. data/app/screens/test_screen.rb +19 -3
  10. data/lib/ProMotion.rb +0 -8
  11. data/lib/ProMotion/version.rb +1 -1
  12. metadata +32 -31
  13. data/.c9revisions/lib/ProMotion.rb.c9save +0 -1
  14. data/.c9revisions/lib/ProMotion/AppDelegate.rb.c9save +0 -3
  15. data/.c9revisions/lib/ProMotion/classes/Screen.rb.c9save +0 -2
  16. data/lib/ProMotion/AppDelegate.rb +0 -60
  17. data/lib/ProMotion/Console.rb +0 -19
  18. data/lib/ProMotion/ProMotion.rb +0 -3
  19. data/lib/ProMotion/_ext/NavigationController.rb +0 -7
  20. data/lib/ProMotion/_ext/TableViewCell.rb +0 -16
  21. data/lib/ProMotion/_ext/TableViewController.rb +0 -54
  22. data/lib/ProMotion/_ext/ViewController.rb +0 -68
  23. data/lib/ProMotion/_modules/ScreenElements.rb +0 -31
  24. data/lib/ProMotion/_modules/ScreenNavigation.rb +0 -149
  25. data/lib/ProMotion/classes/Element.rb +0 -14
  26. data/lib/ProMotion/classes/Screen.rb +0 -206
  27. data/lib/ProMotion/classes/TableScreen.rb +0 -52
  28. data/lib/ProMotion/helpers/MeasureHelper.rb +0 -18
  29. data/lib/ProMotion/helpers/TabBar.rb +0 -99
  30. data/lib/ProMotion/helpers/ViewHelper.rb +0 -23
  31. data/lib/ProMotion/helpers/motion-table/1st/searchable_table.rb +0 -58
  32. data/lib/ProMotion/helpers/motion-table/1st/sectioned_table.rb +0 -219
  33. data/lib/ProMotion/helpers/motion-table/2nd/grouped_table.rb +0 -12
  34. data/lib/ProMotion/helpers/motion-table/2nd/plain_table.rb +0 -13
  35. data/lib/ProMotion/helpers/motion-table/console.rb +0 -26
  36. data/lib/ProMotion/helpers/system_helper.rb +0 -29
@@ -1,149 +0,0 @@
1
- module ProMotion
2
- module ScreenNavigation
3
- def open_screen(screen, args = {})
4
- # Instantiate screen if given a class instead
5
- screen = screen.new if screen.respond_to?(:new)
6
-
7
- screen.parent_screen = self
8
- screen.view_controller.title = args[:title] if args[:title]
9
-
10
- screen.add_nav_bar if args[:nav_bar]
11
-
12
- unless args[:close_all] || args[:modal]
13
- screen.navigation_controller ||= self.navigation_controller
14
- screen.tab_bar ||= self.tab_bar
15
- end
16
-
17
- screen.modal = args[:modal] if args[:modal]
18
- screen.send(:on_load) if screen.respond_to?(:on_load)
19
- screen.view_controller.hidesBottomBarWhenPushed = args[:hide_tab_bar] if args[:hide_tab_bar]
20
-
21
- if args[:close_all]
22
- fresh_start(screen)
23
- elsif args[:modal]
24
- self.view_controller.presentModalViewController(screen.main_controller, animated:true)
25
- elsif args[:in_tab] && self.tab_bar
26
- vc = open_tab(args[:in_tab])
27
- # $stderr.puts "Found a #{vc.to_s}"
28
- if vc
29
- if vc.is_a?(UINavigationController)
30
- screen.navigation_controller = vc
31
- push_view_controller(screen.view_controller, vc)
32
- else
33
- self.tab_bar.selectedIndex = vc.tabBarItem.tag
34
- $stderr.puts "#{self.tab_bar.selectedIndex} is selected and should be #{vc.tabBarItem.tag}"
35
- # PM::TabBar.replace_current_item(self.tab_bar, view_controller: screen.view_controller)
36
- # TODO: This doesn't work yet.
37
- end
38
- else
39
- $stderr.puts "No tab bar item '#{args[:in_tab]}'"
40
- end
41
- elsif self.navigation_controller
42
- push_view_controller screen.view_controller
43
- else
44
- open_view_controller screen.main_controller
45
- end
46
-
47
- if screen.respond_to?(:on_opened)
48
- screen.send(:on_opened)
49
- end
50
- end
51
-
52
- def fresh_start(screen)
53
- app_delegate.fresh_start(screen)
54
- end
55
-
56
- def app_delegate
57
- UIApplication.sharedApplication.delegate
58
- end
59
-
60
- def close_screen(args = {})
61
- args ||= {}
62
-
63
- # Pop current view, maybe with arguments, if in navigation controller
64
- previous_screen = self.parent_screen
65
- if self.is_modal?
66
- self.parent_screen.view_controller.dismissModalViewControllerAnimated(true)
67
- elsif self.navigation_controller
68
- if args[:to_screen]
69
- self.navigation_controller.popToViewController(args[:to_screen].view_controller, animated: true)
70
- previous_screen = args[:to_screen]
71
- else
72
- self.navigation_controller.popViewControllerAnimated(true)
73
- end
74
- else
75
- Console.log("Tried to close #{self.to_s}; however, this screen isn't modal or in a nav bar.", withColor: Console::PURPLE_COLOR)
76
- end
77
-
78
- if previous_screen && previous_screen.respond_to?(:on_return)
79
- if args
80
- previous_screen.send(:on_return, args)
81
- else
82
- previous_screen.send(:on_return)
83
- end
84
- end
85
- end
86
-
87
- def tab_bar_controller(*screens)
88
- tab_bar_controller = UITabBarController.alloc.init
89
-
90
- view_controllers = []
91
- tag_index = 0
92
- screens.each do |s|
93
- if s.is_a? Screen
94
- s = s.new if s.respond_to?(:new)
95
- s.view_controller.tabBarItem.tag = tag_index
96
- view_controllers << s.main_controller
97
- tag_index += 1
98
- else
99
- Console.log("Non-Screen passed into tab_bar_controller: #{s.to_s}", withColor: Console::RED_COLOR)
100
- end
101
- end
102
-
103
- tab_bar_controller.viewControllers = view_controllers
104
- tab_bar_controller
105
- end
106
-
107
- # Open a UITabBarController with the specified screens as the
108
- # root view controller of the current app.
109
- # @param [Array] A comma-delimited list of screen classes or instances.
110
- # @return [UITabBarController] (this may change in the future; please
111
- # do not rely on it right now)
112
- def open_tab_bar(*screens)
113
- tab_bar = tab_bar_controller(*screens)
114
-
115
- screens.each do |s|
116
- s.parent_screen = self if s.respond_to?("parent_screen=")
117
- s.tab_bar = tab_bar
118
- s.on_load if s.respond_to?(:on_load)
119
- end
120
-
121
- open_view_controller(tab_bar)
122
-
123
- screens.each do |s|
124
- s.on_opened if s.respond_to?(:on_opened)
125
- end
126
-
127
- tab_bar
128
- end
129
-
130
- def open_tab(tab)
131
- if tab.is_a? String
132
- return PM::TabBar.select(self.tab_bar, title: tab)
133
- else
134
- $stderr.puts "Unable to open tab #{tab.to_s} because it isn't a string."
135
- end
136
- end
137
-
138
- def open_view_controller(vc)
139
- UIApplication.sharedApplication.delegate.load_root_view vc
140
- end
141
-
142
- def push_view_controller(vc, nav_controller=nil)
143
- # vc.hidesBottomBarWhenPushed = true if args[:hide_tab_bar]
144
- Console.log(" You need a nav_bar if you are going to push #{vc.to_s} onto it.", withColor: Console::RED_COLOR) unless self.navigation_controller
145
- nav_controller ||= self.navigation_controller
146
- nav_controller.pushViewController(vc, animated: true)
147
- end
148
- end
149
- end
@@ -1,14 +0,0 @@
1
- module ProMotion
2
- class Element
3
- attr_accessor :view
4
-
5
- def initialize(with_view)
6
- self.view = with_view
7
- self
8
- end
9
-
10
- def remove
11
- self.view.removeFromSuperview
12
- end
13
- end
14
- end
@@ -1,206 +0,0 @@
1
- module ProMotion
2
- # Instance methods
3
- class Screen
4
- include ProMotion::ScreenNavigation
5
- include ProMotion::ScreenElements
6
- include ProMotion::SystemHelper
7
-
8
- attr_accessor :view_controller, :navigation_controller, :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
9
-
10
- def initialize(args = {})
11
- args.each do |k, v|
12
- self.send("#{k}=", v) if self.respond_to?("#{k}=")
13
- end
14
- self.load_view_controller
15
- self.view_controller.title = self.title
16
-
17
- self.add_nav_bar if args[:nav_bar]
18
- self.on_init if self.respond_to?(:on_init)
19
- self
20
- end
21
-
22
- def is_modal?
23
- self.modal == true
24
- end
25
-
26
- def has_nav_bar?
27
- self.navigation_controller.nil? != true
28
- end
29
-
30
- # Note: this is overridden in TableScreen
31
- def load_view_controller
32
- self.view_controller ||= ViewController
33
- end
34
-
35
- def set_tab_bar_item(args = {})
36
- self.tab_bar_item = args
37
- refresh_tab_bar_item
38
- end
39
-
40
- def refresh_tab_bar_item
41
- self.main_controller.tabBarItem = ProMotion::TabBar.tab_bar_item(self.tab_bar_item) if self.tab_bar_item
42
- end
43
-
44
- def add_nav_bar
45
- self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)
46
- self.first_screen = true
47
- end
48
-
49
- def set_nav_bar_right_button(title, args={})
50
- args[:style] ||= UIBarButtonItemStyleBordered
51
- args[:target] ||= self
52
- args[:action] ||= nil
53
-
54
- right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
55
- self.view_controller.navigationItem.rightBarButtonItem = right_button
56
- right_button
57
- end
58
-
59
- def set_nav_bar_left_button(title, args={})
60
- args[:style] ||= UIBarButtonItemStyleBordered
61
- args[:target] ||= self
62
- args[:action] ||= nil
63
-
64
- left_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
65
- self.view_controller.navigationItem.leftBarButtonItem = left_button
66
- left_button
67
- end
68
-
69
- def view_controller=(vc)
70
- vc = vc.alloc.initWithNibName(nil, bundle:nil) if vc.respond_to?(:alloc)
71
- if self.navigation_controller && self.first_screen?
72
- @view_controller = vc
73
- self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)
74
- else
75
- @view_controller = vc
76
- end
77
- @view_controller.screen = self if @view_controller.respond_to?("screen=")
78
-
79
- refresh_tab_bar_item
80
- end
81
-
82
- def first_screen?
83
- self.first_screen == true
84
- end
85
-
86
- def set_view_controller(vc)
87
- self.view_controller = vc
88
- end
89
-
90
- def view_did_load; end
91
- def on_opened; end
92
-
93
- def view_will_appear(animated)
94
- ProMotion::Screen.current_screen = self
95
- self.will_appear
96
- end
97
- def will_appear; end
98
-
99
- def view_did_appear(animated)
100
- ProMotion::Screen.current_screen = self
101
- self.on_appear
102
- end
103
- def on_appear; end
104
-
105
- def view_will_disappear(animated)
106
- self.will_disappear
107
- end
108
- def will_disappear; end
109
-
110
- def view_did_disappear(animated)
111
- self.on_disappear
112
- end
113
- def on_disappear; end
114
-
115
- def title
116
- self.class.send(:get_title)
117
- end
118
-
119
- def title=(new_title)
120
- self.class.title = new_title
121
- self.view_controller.title = new_title if self.view_controller
122
- end
123
-
124
- def main_controller
125
- return self.navigation_controller if self.navigation_controller
126
- self.view_controller
127
- end
128
-
129
- def should_rotate(orientation)
130
- case orientation
131
- when UIInterfaceOrientationPortrait
132
- return supported_orientation?("UIInterfaceOrientationPortrait")
133
- when UIInterfaceOrientationLandscapeLeft
134
- return supported_orientation?("UIInterfaceOrientationLandscapeLeft")
135
- when UIInterfaceOrientationLandscapeRight
136
- return supported_orientation?("UIInterfaceOrientationLandscapeRight")
137
- when UIInterfaceOrientationPortraitUpsideDown
138
- return supported_orientation?("UIInterfaceOrientationPortraitUpsideDown")
139
- else
140
- false
141
- end
142
- end
143
-
144
- def will_rotate(orientation, duration)
145
- end
146
-
147
- def should_autorotate
148
- false
149
- end
150
-
151
- def on_rotate
152
- end
153
-
154
- def supported_orientation?(orientation)
155
- NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].include?(orientation)
156
- end
157
-
158
- def supported_orientations
159
- ors = 0
160
- NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
161
- case ori
162
- when "UIInterfaceOrientationPortrait"
163
- ors |= UIInterfaceOrientationMaskPortrait
164
- when "UIInterfaceOrientationLandscapeLeft"
165
- ors |= UIInterfaceOrientationMaskLandscapeLeft
166
- when "UIInterfaceOrientationLandscapeRight"
167
- ors |= UIInterfaceOrientationMaskLandscapeRight
168
- when "UIInterfaceOrientationPortraitUpsideDown"
169
- ors |= UIInterfaceOrientationMaskPortraitUpsideDown
170
- end
171
- end
172
- ors
173
- end
174
- end
175
-
176
- # Class methods
177
- class Screen
178
- class << self
179
- def debug_mode
180
- @debug_mode
181
- end
182
-
183
- def debug_mode=(v)
184
- @debug_mode = v
185
- end
186
-
187
- def current_screen=(s)
188
- @current_screen = s
189
- end
190
-
191
- def current_screen
192
- @current_screen
193
- end
194
-
195
- def title(t)
196
- @title = t
197
- end
198
- def title=(t)
199
- @title = t
200
- end
201
- def get_title
202
- @title ||= self.to_s
203
- end
204
- end
205
- end
206
- end
@@ -1,52 +0,0 @@
1
- module ProMotion
2
- # Instance methods
3
- class TableScreen < Screen
4
- include MotionTable::PlainTable
5
- include MotionTable::SearchableTable
6
-
7
- def view
8
- self.view_controller.view
9
- end
10
-
11
- def load_view_controller
12
- check_table_data_method
13
-
14
- self.view_controller ||= TableViewController
15
- self.view_controller.view = self.createTableViewFromData(self.table_data)
16
- if self.class.get_searchable
17
- self.makeSearchable(contentController: self.view_controller, searchBar: self.class.get_searchable_params)
18
- end
19
- end
20
-
21
- def check_table_data_method
22
- Console.log("- table_data method needed in table view screen.", withColor: Console::RED_COLOR) unless self.respond_to?(:table_data)
23
- end
24
-
25
- def update_table_data
26
- self.updateTableViewData(table_data)
27
- end
28
-
29
- class << self
30
- def searchable(params={})
31
- @searchable_params = params
32
- @searchable = true
33
- end
34
-
35
- def get_searchable_params
36
- @searchable_params ||= nil
37
- end
38
-
39
- def get_searchable
40
- @searchable ||= false
41
- end
42
- end
43
- end
44
-
45
- class GroupedTableScreen < TableScreen
46
- include MotionTable::GroupedTable
47
- end
48
-
49
- class SectionedTableScreen < TableScreen
50
- include MotionTable::SectionedTable
51
- end
52
- end
@@ -1,18 +0,0 @@
1
- module ProMotion
2
- class MeasureHelper
3
- class << self
4
- def content_height(view)
5
- height = 0
6
- view.subviews.each do |sub_view|
7
- next if sub_view.isHidden
8
- y = sub_view.frame.origin.y
9
- h = sub_view.frame.size.height
10
- if (y + h) > height
11
- height = y + h
12
- end
13
- end
14
- height
15
- end
16
- end
17
- end
18
- end
@@ -1,99 +0,0 @@
1
- module ProMotion
2
- class TabBar
3
- class << self
4
- def create_tab_bar_controller_from_data(data)
5
- data = self.setTags(data)
6
-
7
- tabBarController = UITabBarController.alloc.init
8
- tabBarController.viewControllers = self.tab_controllers_from_data(data)
9
-
10
- return tabBarController
11
- end
12
-
13
- def set_tags(data)
14
- tag_number = 0
15
-
16
- data.each do |d|
17
- d[:tag] = tag_number
18
- tag_number += 1
19
- end
20
-
21
- return data
22
- end
23
-
24
- def tab_bar_icon(icon, tag)
25
- return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
26
- end
27
-
28
- def tab_bar_icon_custom(title, image_name, tag)
29
- icon_image = UIImage.imageNamed(image_name)
30
- return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag)
31
- end
32
-
33
- def tab_controllers_from_data(data)
34
- mt_tab_controllers = []
35
-
36
- data.each do |tab|
37
- mt_tab_controllers << self.controller_from_tab_data(tab)
38
- end
39
-
40
- return mt_tab_controllers
41
- end
42
-
43
- def controller_from_tab_data(tab)
44
- tab[:badgeNumber] = 0 unless tab[:badgeNumber]
45
- tab[:tag] = 0 unless tab[:tag]
46
-
47
- view_controller = tab[:view_controller]
48
- view_controller = tab[:view_controller].alloc.init if tab[:view_controller].respond_to?(:alloc)
49
-
50
- if tab[:navigationController]
51
- controller = UINavigationController.alloc.initWithRootViewController(view_controller)
52
- else
53
- controller = view_controller
54
- end
55
-
56
- controller.tabBarItem = self.tabBarItem(tab)
57
- controller.tabBarItem.title = controller.title unless tab[:title]
58
-
59
- return controller
60
- end
61
-
62
- def tab_bar_item(tab)
63
- title = "Untitled"
64
- title = tab[:title] if tab[:title]
65
- tab[:tag] ||= @current_tag ||= 0
66
- @current_tag = tab[:tag] + 1
67
-
68
- tab_bar_item = tab_bar_icon(tab[:system_icon], tab[:tag]) if tab[:system_icon]
69
- tab_bar_item = tab_bar_icon_custom(title, tab[:icon], tab[:tag]) if tab[:icon]
70
-
71
- tab_bar_item.badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0
72
-
73
- return tab_bar_item
74
- end
75
-
76
- def select(tab_bar_controller, title: title)
77
- root_controller = nil
78
- tab_bar_controller.viewControllers.each do |vc|
79
- if vc.tabBarItem.title == title
80
- tab_bar_controller.selectedViewController = vc
81
- root_controller = vc
82
- break
83
- end
84
- end
85
- root_controller
86
- end
87
-
88
- def select(tab_bar_controller, tag: tag)
89
- tab_bar_controller.selectedIndex = tag
90
- end
91
-
92
- def replace_current_item(tab_bar_controller, view_controller: vc)
93
- controllers = NSMutableArray.arrayWithArray(tab_bar_controller.viewControllers)
94
- controllers.replaceObjectAtIndex(tab_bar_controller.selectedIndex, withObject: vc)
95
- tab_bar_controller.viewControllers = controllers
96
- end
97
- end
98
- end
99
- end