ProMotion 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ {"ts":1347898586630,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"unless defined?(Motion::Project::Config)\n raise \"This file must be required within a RubyMotion project Rakefile.\"\nend\n\nrequire \"ProMotion/version\"\n\nMotion::Project::App.setup do |app|\n\n # Dir.glob(File.join(File.dirname(__FILE__), \"ProMotion/**/*.rb\")).each do |file|\n # app.files.unshift(file)\n # end\n app.files = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/**/*.rb')) | app.files\n app.files = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/helpers/**/*.rb')) | app.files\n app.files = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/modules/**/*.rb')) | app.files\n app.files = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/ext/**/*.rb')) | app.files\n \nend"]],"start1":0,"start2":0,"length1":0,"length2":699}]],"length":699}
@@ -0,0 +1,3 @@
1
+ {"ts":1347924907908,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"module ProMotion\n class AppDelegateParent\n attr_accessor :window\n \n def application(application, didFinishLaunchingWithOptions:launchOptions)\n return true if RUBYMOTION_ENV == \"test\"\n\n Console.log(\" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.\", withColor: Console::RED_COLOR) unless self.respond_to?(:on_load)\n \n on_load launchOptions\n\n open_home_screen if has_home_screen\n\n get_home_screen.on_opened if has_home_screen && get_home_screen.respond_to?(:on_opened)\n \n true\n end\n\n def app_delegate\n UIApplication.sharedApplication.delegate\n end\n\n def app_window\n self.app_delegate.window\n end\n\n def load_root_view(new_view)\n self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)\n self.window.rootViewController = new_view\n self.window.makeKeyAndVisible\n end\n\n def open_screen(screen)\n home(screen)\n end\n\n def home(screen)\n screen = screen.new if screen.respond_to? :new\n @home_screen = screen\n end\n\n def fresh_start(new_screen)\n home(new_screen)\n open_home_screen\n end\n\n def open_home_screen\n get_home_screen.send(:on_load) if get_home_screen.respond_to?(:on_load)\n load_root_view get_home_screen.main_controller\n end\n \n def get_home_screen\n @home_screen\n end\n\n def has_home_screen\n @home_screen.nil? == false\n end\n end\nend"]],"start1":0,"start2":0,"length1":0,"length2":1456}]],"length":1456}
2
+ {"contributors":[],"silentsave":false,"ts":1347925005943,"patch":[[{"diffs":[[0,"_to?"],[-1," "],[1,"("],[0,":new"],[1,")s"],[0,"\n "]],"start1":1027,"start2":1027,"length1":13,"length2":15}]],"length":1458,"saved":false}
3
+ {"ts":1347925017979,"patch":[[{"diffs":[[0,"o?(:new)"],[-1,"s"],[0,"\n @"]],"start1":1029,"start2":1029,"length1":17,"length2":16}]],"length":1457,"saved":false}
@@ -0,0 +1,2 @@
1
+ {"ts":1347898745792,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"module ProMotion\n # Instance methods\n class Screen\n include ProMotion::ScreenNavigation\n include ProMotion::ScreenElements\n \n attr_accessor :view_controller, :navigation_controller, :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal\n\n def initialize(args = {})\n args.each do |k, v|\n self.send \"#{k}=\", v if self.respond_to?(\"#{k}=\")\n end\n self.load_view_controller\n self.view_controller.title = self.title\n\n self.add_nav_bar if args[:nav_bar]\n self.on_init if self.respond_to?(:on_init)\n self\n end\n\n def is_modal?\n self.modal == true\n end\n\n def has_nav_bar?\n self.navigation_controller.nil? != true\n end\n\n # Note: this is overridden in TableScreen\n def load_view_controller\n self.view_controller ||= ViewController\n end\n\n def set_tab_bar_item(args = {})\n self.tab_bar_item = args\n refresh_tab_bar_item\n end\n\n def refresh_tab_bar_item\n self.main_controller.tabBarItem = ProMotion::TabBar.tab_bar_item(self.tab_bar_item) if self.tab_bar_item\n end\n \n def add_nav_bar\n self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)\n self.first_screen = true\n end\n\n def set_nav_bar_right_button(title, args={})\n args[:style] ||= UIBarButtonItemStyleBordered\n args[:target] ||= self\n args[:action] ||= nil\n\n right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])\n self.view_controller.navigationItem.rightBarButtonItem = right_button\n right_button\n end\n\n def set_nav_bar_left_button(title, args={})\n args[:style] ||= UIBarButtonItemStyleBordered\n args[:target] ||= self\n args[:action] ||= nil\n\n left_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])\n self.view_controller.navigationItem.leftBarButtonItem = left_button\n left_button\n end\n\n def view_controller=(vc)\n vc = vc.alloc.initWithNibName(nil, bundle:nil) if vc.respond_to?(:alloc)\n if self.navigation_controller && self.first_screen?\n @view_controller = vc\n self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)\n else\n @view_controller = vc\n end\n @view_controller.screen = self if @view_controller.respond_to?(\"screen=\")\n\n refresh_tab_bar_item\n end\n\n def first_screen?\n self.first_screen == true\n end\n\n def set_view_controller(vc)\n self.view_controller = vc\n end\n\n def view_will_appear(animated)\n self.will_appear if self.respond_to?(:will_appear)\n end\n\n def view_did_appear(animated)\n self.on_appear if self.respond_to?(:on_appear)\n end\n\n def title\n self.class.send :get_title\n end\n\n def title=(new_title)\n self.class.title = new_title\n self.view_controller.title = new_title\n end\n\n def main_controller\n return self.navigation_controller if self.navigation_controller\n self.view_controller\n end\n\n end\n \n # Class methods\n class Screen\n class << self\n def title(t)\n @title = t\n end\n def title=(t)\n @title = t\n end\n def get_title\n @title ||= self.to_s\n end\n end\n end\nend"]],"start1":0,"start2":0,"length1":0,"length2":3387}]],"length":3387}
2
+ {"contributors":[],"silentsave":false,"ts":1347898870641,"patch":[[{"diffs":[[0,"lements\n"],[-1," "],[0,"\n att"]],"start1":123,"start2":123,"length1":20,"length2":16},{"diffs":[[0," end\n"],[-1," "],[0,"\n def"]],"start1":1070,"start2":1070,"length1":20,"length2":16},{"diffs":[[0,"\n\n end\n"],[-1," "],[0,"\n # Cla"]],"start1":3144,"start2":3144,"length1":18,"length2":16}]],"length":3377,"saved":false}
data/README.md CHANGED
@@ -3,19 +3,19 @@
3
3
  ProMotion introduces a new object called "Screens". Screens have a one-to-one relationship
4
4
  with your app's screens and can (usually) take the place of view controllers.
5
5
 
6
- Typical /app file structure:
6
+ Typical app file structure:
7
7
 
8
- app
9
- screens
10
- photos
8
+ app/
9
+ screens/
10
+ photos/
11
11
  list_photos_screen.rb
12
12
  show_photo_screen.rb
13
13
  edit_photo_screen.rb
14
14
  home_screen.rb
15
15
  settings_screen.rb
16
- models
17
- view_controllers
18
- views
16
+ models/
17
+ view_controllers/
18
+ views/
19
19
  app_delegate.rb
20
20
 
21
21
  ## Usage
@@ -120,7 +120,7 @@ end
120
120
 
121
121
  ```
122
122
 
123
- Close a screen, passing back arguments to the previous screen's "on_return" method:
123
+ Close a screen (modal or in a nav controller), passing back arguments to the previous screen's "on_return" method:
124
124
 
125
125
  ```ruby
126
126
  class ItemScreen
@@ -167,7 +167,9 @@ it to the current view. Screens include this helper by default.
167
167
  }
168
168
  ```
169
169
 
170
- You can create sectioned table screens easily. TableScreen, SectionedTableScreen, GroupedTableScreen
170
+ You can create sectioned table screens easily. TableScreen, SectionedTableScreen, GroupedTableScreen.
171
+ This is loosely based on [motion-table](https://github.com/clearsightstudio/motion-table) (there are a
172
+ few minor differences).
171
173
 
172
174
  ```ruby
173
175
  class SettingsScreen < ProMotion::GroupedTableScreen
@@ -209,12 +211,42 @@ class SettingsScreen < ProMotion::GroupedTableScreen
209
211
  end
210
212
  ```
211
213
 
214
+ # Reference
215
+ (not comprehensive yet...working on this)
216
+
217
+ <table>
218
+ <tr>
219
+ <th>Class or Module</th>
220
+ <th>Method</th>
221
+ <th>Description</th>
222
+ </tr>
223
+ <tr>
224
+ <td>Screen</td>
225
+ <td>is_modal?</td>
226
+ <td>Returns if the screen was opened in a modal window.</td>
227
+ </tr>
228
+ <tr>
229
+ <td>&nbsp;</td>
230
+ <td>has_nav_bar?</td>
231
+ <td>Returns if the screen is contained in a navigation controller.</td>
232
+ </tr>
233
+ <tr>
234
+ <td>&nbsp;</td>
235
+ <td>set_tab_bar_item(args)</td>
236
+ <td>
237
+ Creates the tab that is shown in a tab bar item.<br />
238
+ Arguments: <code>{ icon: "imagename", systemIcon: UISystemIconContacts, title: "tabtitle" }</code>
239
+ </td>
240
+ </tr>
241
+ </table>
242
+
212
243
  ### What about MVC?
213
244
 
214
245
  I'm a big believer in MVC (I'm a Rails developer, too). I found that most of the time working in RubyMotion seems to happen
215
- in the ViewControllers and views are mainly custom elements. This pattern may be best for simpler, smaller apps.
246
+ in the ViewControllers and views are mainly custom elements. This pattern is probably best for navigation controller and
247
+ tab bar based apps.
216
248
 
217
- Feedback welcome via twitter @jamonholmgren.
249
+ Feedback welcome via twitter @jamonholmgren or email jamon@clearsightstudio.com.
218
250
 
219
251
  ## Contributing
220
252
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'motion-table'
8
8
  Motion::Project::App.setup do |app|
9
9
  # Use `rake config' to see complete project settings.
10
10
  app.name = 'ProMotionTest'
11
- app.version = "0.1.0"
11
+ app.version = "0.2.0"
12
12
 
13
13
 
14
14
  # Devices
@@ -5,7 +5,7 @@ module ProMotion
5
5
  def application(application, didFinishLaunchingWithOptions:launchOptions)
6
6
  return true if RUBYMOTION_ENV == "test"
7
7
 
8
- Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.", withColor: Console::RED_COLOR) unless self.respond_to? :on_load
8
+ Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.", withColor: Console::RED_COLOR) unless self.respond_to?(:on_load)
9
9
 
10
10
  on_load launchOptions
11
11
 
@@ -35,7 +35,7 @@ module ProMotion
35
35
  end
36
36
 
37
37
  def home(screen)
38
- screen = screen.new if screen.respond_to? :new
38
+ screen = screen.new if screen.respond_to?(:new)
39
39
  @home_screen = screen
40
40
  end
41
41
 
@@ -2,33 +2,49 @@ module ProMotion
2
2
  module ScreenNavigation
3
3
  def open_screen(screen, args = {})
4
4
  # Instantiate screen if given a class instead
5
- screen = screen.new if screen.respond_to? :new
5
+ screen = screen.new if screen.respond_to?(:new)
6
6
 
7
7
  screen.parent_screen = self
8
8
  screen.view_controller.title = args[:title] if args[:title]
9
9
 
10
10
  screen.add_nav_bar if args[:nav_bar]
11
+
11
12
  unless args[:close_all] || args[:modal]
12
13
  screen.navigation_controller ||= self.navigation_controller
14
+ screen.tab_bar ||= self.tab_bar
13
15
  end
14
-
15
- screen.main_controller.hidesBottomBarWhenPushed = args[:hide_tab_bar] if args[:hide_tab_bar]
16
16
 
17
17
  screen.modal = args[:modal] if args[:modal]
18
-
19
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
20
 
21
21
  if args[:close_all]
22
22
  fresh_start(screen)
23
23
  elsif args[:modal]
24
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
+ push_view_controller(screen.view_controller, vc)
31
+ else
32
+ self.tab_bar.selectedIndex = vc.tabBarItem.tag
33
+ $stderr.puts "#{self.tab_bar.selectedIndex} is selected and should be #{vc.tabBarItem.tag}"
34
+ # PM::TabBar.replace_current_item(self.tab_bar, view_controller: screen.view_controller)
35
+ end
36
+ else
37
+ $stderr.puts "No tab bar item '#{args[:in_tab]}'"
38
+ end
25
39
  elsif self.navigation_controller
26
40
  push_view_controller screen.view_controller
27
41
  else
28
42
  open_view_controller screen.main_controller
29
43
  end
30
44
 
31
- screen.send(:on_opened) if screen.respond_to?(:on_opened)
45
+ if screen.respond_to?(:on_opened)
46
+ screen.send(:on_opened)
47
+ end
32
48
  end
33
49
 
34
50
  def fresh_start(screen)
@@ -64,10 +80,13 @@ module ProMotion
64
80
  tab_bar_controller = UITabBarController.alloc.init
65
81
 
66
82
  view_controllers = []
83
+ tag_index = 0
67
84
  screens.each do |s|
68
85
  if s.is_a? Screen
69
- s = s.new if s.respond_to? :new
86
+ s = s.new if s.respond_to?(:new)
87
+ s.view_controller.tabBarItem.tag = tag_index
70
88
  view_controllers << s.main_controller
89
+ tag_index += 1
71
90
  else
72
91
  Console.log("Non-Screen passed into tab_bar_controller: #{s.to_s}", withColor: Console::RED_COLOR)
73
92
  end
@@ -77,48 +96,47 @@ module ProMotion
77
96
  tab_bar_controller
78
97
  end
79
98
 
99
+ # Open a UITabBarController with the specified screens as the
100
+ # root view controller of the current app.
101
+ # @param [Array] A comma-delimited list of screen classes or instances.
102
+ # @return [UITabBarController] (this may change in the future; please
103
+ # do not rely on it right now)
80
104
  def open_tab_bar(*screens)
81
105
  tab_bar = tab_bar_controller(*screens)
82
106
 
83
107
  screens.each do |s|
84
- s.parent_screen = self if s.respond_to? "parent_screen="
85
- s.on_load if s.respond_to? :on_load
108
+ s.parent_screen = self if s.respond_to?("parent_screen=")
109
+ s.tab_bar = tab_bar
110
+ s.on_load if s.respond_to?(:on_load)
86
111
  end
87
112
 
88
- open_view_controller tab_bar
113
+ open_view_controller(tab_bar)
89
114
 
90
115
  screens.each do |s|
91
- s.on_opened if s.respond_to? :on_opened
116
+ s.on_opened if s.respond_to?(:on_opened)
92
117
  end
93
118
 
94
119
  tab_bar
95
120
  end
96
121
 
97
- def push_tab_bar(*screens)
98
- tab_bar = tab_bar_controller(*screens)
99
-
100
- screens.each do |s|
101
- s.parent_screen = self if s.respond_to? "parent_screen="
102
- s.on_load if s.respond_to? :on_load
103
- end
104
-
105
- push_view_controller tab_bar
106
-
107
- screens.each do |s|
108
- s.on_opened if s.respond_to? :on_opened
122
+ def open_tab(tab)
123
+ if tab.is_a? String
124
+ $stderr.puts "Opening tab in #{self.tab_bar.to_s} : #{tab}"
125
+ return PM::TabBar.select(self.tab_bar, title: tab)
126
+ else
127
+ $stderr.puts "Unable to open tab #{tab.to_s} because it isn't a string."
109
128
  end
110
-
111
- tab_bar
112
129
  end
113
130
 
114
131
  def open_view_controller(vc)
115
132
  UIApplication.sharedApplication.delegate.load_root_view vc
116
133
  end
117
134
 
118
- def push_view_controller(vc)
135
+ def push_view_controller(vc, nav_controller=nil)
119
136
  # vc.hidesBottomBarWhenPushed = true if args[:hide_tab_bar]
120
137
  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
121
- self.navigation_controller.pushViewController(vc, animated: true)
138
+ nav_controller ||= self.navigation_controller
139
+ nav_controller.pushViewController(vc, animated: true)
122
140
  end
123
141
  end
124
142
  end
@@ -3,23 +3,22 @@ module ProMotion
3
3
  class Screen
4
4
  include ProMotion::ScreenNavigation
5
5
  include ProMotion::ScreenElements
6
-
7
- attr_accessor :view_controller, :navigation_controller, :parent_screen, :first_screen, :tab_bar_item, :modal
6
+
7
+ attr_accessor :view_controller, :navigation_controller, :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
8
8
 
9
9
  def initialize(args = {})
10
10
  args.each do |k, v|
11
- self.send "#{k}=", v if self.respond_to? "#{k}="
11
+ self.send "#{k}=", v if self.respond_to?("#{k}=")
12
12
  end
13
13
  self.load_view_controller
14
14
  self.view_controller.title = self.title
15
15
 
16
16
  self.add_nav_bar if args[:nav_bar]
17
- self.on_init if self.respond_to? :on_init
17
+ self.on_init if self.respond_to?(:on_init)
18
18
  self
19
19
  end
20
20
 
21
21
  def is_modal?
22
- $stderr.puts self.modal
23
22
  self.modal == true
24
23
  end
25
24
 
@@ -40,7 +39,7 @@ module ProMotion
40
39
  def refresh_tab_bar_item
41
40
  self.main_controller.tabBarItem = ProMotion::TabBar.tab_bar_item(self.tab_bar_item) if self.tab_bar_item
42
41
  end
43
-
42
+
44
43
  def add_nav_bar
45
44
  self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)
46
45
  self.first_screen = true
@@ -67,14 +66,14 @@ module ProMotion
67
66
  end
68
67
 
69
68
  def view_controller=(vc)
70
- vc = vc.alloc.initWithNibName(nil, bundle:nil) if vc.respond_to? :alloc
69
+ vc = vc.alloc.initWithNibName(nil, bundle:nil) if vc.respond_to?(:alloc)
71
70
  if self.navigation_controller && self.first_screen?
72
71
  @view_controller = vc
73
72
  self.navigation_controller = NavigationController.alloc.initWithRootViewController(self.view_controller)
74
73
  else
75
74
  @view_controller = vc
76
75
  end
77
- @view_controller.screen = self if @view_controller.respond_to? "screen="
76
+ @view_controller.screen = self if @view_controller.respond_to?("screen=")
78
77
 
79
78
  refresh_tab_bar_item
80
79
  end
@@ -88,11 +87,11 @@ module ProMotion
88
87
  end
89
88
 
90
89
  def view_will_appear(animated)
91
- self.will_appear if self.respond_to? :will_appear
90
+ self.will_appear if self.respond_to?(:will_appear)
92
91
  end
93
92
 
94
93
  def view_did_appear(animated)
95
- self.on_appear if self.respond_to? :on_appear
94
+ self.on_appear if self.respond_to?(:on_appear)
96
95
  end
97
96
 
98
97
  def title
@@ -110,7 +109,7 @@ module ProMotion
110
109
  end
111
110
 
112
111
  end
113
-
112
+
114
113
  # Class methods
115
114
  class Screen
116
115
  class << self
@@ -5,7 +5,7 @@ module ProMotion
5
5
  include MotionTable::SearchableTable
6
6
 
7
7
  def view
8
- return self.view_controller.view
8
+ self.view_controller.view
9
9
  end
10
10
 
11
11
  def load_view_controller
@@ -19,7 +19,7 @@ module ProMotion
19
19
  end
20
20
 
21
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
22
+ Console.log("- table_data method needed in table view screen.", withColor: Console::RED_COLOR) unless self.respond_to?(:table_data)
23
23
  end
24
24
 
25
25
  def update_table_data
@@ -4,6 +4,8 @@ module ProMotion
4
4
  def content_height(view)
5
5
  height = 0
6
6
  view.subviews.each do |sub_view|
7
+ $stderr.puts sub_view
8
+ next if sub_view.isHidden
7
9
  y = sub_view.frame.origin.y
8
10
  h = sub_view.frame.size.height
9
11
  if (y + h) > height
@@ -1,20 +1,52 @@
1
1
  module ProMotion
2
2
  class TabBar
3
3
  class << self
4
- def tab_bar_item(args = {})
5
- title = "Untitled"
6
- title = args[:title] if args[:title]
7
- args[:tag] ||= 0
4
+ # def tab_bar_item(args = {})
5
+ # title = "Untitled"
6
+ # title = args[:title] if args[:title]
7
+ # args[:tag] ||= 0
8
8
 
9
- tb_item = tab_bar_icon(args[:system_icon], args[:tag]) if args[:system_icon]
10
- tb_item = tab_bar_icon_custom(title, args[:icon], args[:tag]) if args[:icon]
9
+ # tb_item = tab_bar_icon(args[:system_icon], args[:tag]) if args[:system_icon]
10
+ # tb_item = tab_bar_icon_custom(title, args[:icon], args[:tag]) if args[:icon]
11
11
 
12
- if tb_item
13
- tb_item.badgeValue = args[:badge_number].to_s unless args[:badge_number].nil? || tab[:badge_number] <= 0
12
+ # if tb_item
13
+ # tb_item.badgeValue = args[:badge_number].to_s unless args[:badge_number].nil? || tab[:badge_number] <= 0
14
+
15
+ # return tb_item
16
+ # end
17
+ # nil
18
+ # end
19
+
20
+ # def tab_bar_icon(icon, tag)
21
+ # return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
22
+ # end
23
+
24
+ # def tab_bar_icon_custom(title, image_name, tag)
25
+ # icon_image = UIImage.imageNamed(image_name)
26
+ # return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag)
27
+ # end
28
+
14
29
 
15
- return tb_item
30
+
31
+
32
+ def create_tab_bar_controller_from_data(data)
33
+ data = self.setTags(data)
34
+
35
+ tabBarController = UITabBarController.alloc.init
36
+ tabBarController.viewControllers = self.tab_controllers_from_data(data)
37
+
38
+ return tabBarController
39
+ end
40
+
41
+ def set_tags(data)
42
+ tag_number = 0
43
+
44
+ data.each do |d|
45
+ d[:tag] = tag_number
46
+ tag_number += 1
16
47
  end
17
- nil
48
+
49
+ return data
18
50
  end
19
51
 
20
52
  def tab_bar_icon(icon, tag)
@@ -25,6 +57,71 @@ module ProMotion
25
57
  icon_image = UIImage.imageNamed(image_name)
26
58
  return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag)
27
59
  end
60
+
61
+ def tab_controllers_from_data(data)
62
+ mt_tab_controllers = []
63
+
64
+ data.each do |tab|
65
+ mt_tab_controllers << self.controller_from_tab_data(tab)
66
+ end
67
+
68
+ return mt_tab_controllers
69
+ end
70
+
71
+ def controller_from_tab_data(tab)
72
+ tab[:badgeNumber] = 0 unless tab[:badgeNumber]
73
+ tab[:tag] = 0 unless tab[:tag]
74
+
75
+ view_controller = tab[:view_controller]
76
+ view_controller = tab[:view_controller].alloc.init if tab[:view_controller].respond_to?(:alloc)
77
+
78
+ if tab[:navigationController]
79
+ controller = UINavigationController.alloc.initWithRootViewController(view_controller)
80
+ else
81
+ controller = view_controller
82
+ end
83
+
84
+ controller.tabBarItem = self.tabBarItem(tab)
85
+ controller.tabBarItem.title = controller.title unless tab[:title]
86
+
87
+ return controller
88
+ end
89
+
90
+ def tab_bar_item(tab)
91
+ title = "Untitled"
92
+ title = tab[:title] if tab[:title]
93
+ tab[:tag] ||= @current_tag ||= 0
94
+ @current_tag = tab[:tag] + 1
95
+
96
+ tab_bar_item = tab_bar_icon(tab[:system_icon], tab[:tag]) if tab[:system_icon]
97
+ tab_bar_item = tab_bar_icon_custom(title, tab[:icon], tab[:tag]) if tab[:icon]
98
+
99
+ tab_bar_item.badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0
100
+
101
+ return tab_bar_item
102
+ end
103
+
104
+ def select(tab_bar_controller, title: title)
105
+ root_controller = nil
106
+ tab_bar_controller.viewControllers.each do |vc|
107
+ if vc.tabBarItem.title == title
108
+ tab_bar_controller.selectedViewController = vc
109
+ root_controller = vc
110
+ break
111
+ end
112
+ end
113
+ root_controller
114
+ end
115
+
116
+ def select(tab_bar_controller, tag: tag)
117
+ tab_bar_controller.selectedIndex = tag
118
+ end
119
+
120
+ def replace_current_item(tab_bar_controller, view_controller: vc)
121
+ controllers = NSMutableArray.arrayWithArray(tab_bar_controller.viewControllers)
122
+ controllers.replaceObjectAtIndex(tab_bar_controller.selectedIndex, withObject: vc)
123
+ tab_bar_controller.viewControllers = controllers
124
+ end
28
125
  end
29
126
  end
30
127
  end
@@ -2,7 +2,14 @@ module ProMotion
2
2
  module ViewHelper
3
3
  def set_attributes(element, args = {})
4
4
  args.each do |k, v|
5
- element.send("#{k}=", v) if element.respond_to? "#{k}="
5
+ if v.is_a? Hash
6
+ v.each do |k2, v2|
7
+ sub_element = element.send("#{k}")
8
+ sub_element.send("#{k2}=", v2) if sub_element.respond_to?("#{k2}=")
9
+ end
10
+ else
11
+ element.send("#{k}=", v) if element.respond_to?("#{k}=")
12
+ end
6
13
  end
7
14
  element
8
15
  end
@@ -21,9 +21,10 @@ module ProMotion::MotionTable
21
21
  end
22
22
 
23
23
  def searchDisplayController(controller, shouldReloadTableForSearchString:searchString)
24
- @mt_table_view_groups = []
24
+ @mt_filtered_data = nil
25
+ @mt_filtered_data = []
25
26
 
26
- @original_data.each do |section|
27
+ @mt_table_view_groups.each do |section|
27
28
  newSection = {}
28
29
  newSection[:cells] = []
29
30
 
@@ -33,22 +34,25 @@ module ProMotion::MotionTable
33
34
  end
34
35
  end
35
36
 
36
- if newSection.count > 0
37
+ if newSection[:cells] && newSection[:cells].length > 0
37
38
  newSection[:title] = section[:title]
38
- @mt_table_view_groups << newSection
39
+ @mt_filtered_data << newSection
39
40
  end
40
41
  end
41
-
42
+
42
43
  true
43
44
  end
44
45
 
45
46
  def searchDisplayControllerWillEndSearch(controller)
46
- @mt_table_view_groups = @original_data.clone
47
- @original_data = nil
47
+ @mt_filtered = false
48
+ @mt_filtered_data = nil
49
+ self.tableView.setScrollEnabled true
48
50
  end
49
51
 
50
52
  def searchDisplayControllerWillBeginSearch(controller)
51
- @original_data = @mt_table_view_groups.clone
53
+ @mt_filtered = true
54
+ @mt_filtered_data = []
55
+ self.tableView.setScrollEnabled false
52
56
  end
53
57
  end
54
58
  end
@@ -9,7 +9,7 @@ module ProMotion::MotionTable
9
9
 
10
10
  def updateTableViewData(data)
11
11
  setTableViewData data
12
- @tableView.reloadData
12
+ self.tableView.reloadData
13
13
  end
14
14
 
15
15
  def setTableViewData(data)
@@ -17,22 +17,27 @@ module ProMotion::MotionTable
17
17
  end
18
18
 
19
19
  def numberOfSectionsInTableView(tableView)
20
- return @mt_table_view_groups.length if @mt_table_view_groups
20
+ if @mt_filtered
21
+ return @mt_filtered_data.length if @mt_filtered_data
22
+ else
23
+ return @mt_table_view_groups.length if @mt_table_view_groups
24
+ end
21
25
  0
22
26
  end
23
27
 
24
28
  # Number of cells
25
29
  def tableView(tableView, numberOfRowsInSection:section)
26
- return sectionAtIndex(section)[:cells].length
30
+ return sectionAtIndex(section)[:cells].length if sectionAtIndex(section)
31
+ 0
27
32
  end
28
33
 
29
34
  def tableView(tableView, titleForHeaderInSection:section)
30
- return sectionAtIndex(section)[:title]
35
+ return sectionAtIndex(section)[:title] if sectionAtIndex(section)
31
36
  end
32
37
 
33
38
  # Set table_data_index if you want the right hand index column (jumplist)
34
39
  def sectionIndexTitlesForTableView(tableView)
35
- self.table_data_index if respond_to? :table_data_index
40
+ self.table_data_index if respond_to?(:table_data_index)
36
41
  end
37
42
 
38
43
  def tableView(tableView, cellForRowAtIndexPath:indexPath)
@@ -59,6 +64,7 @@ module ProMotion::MotionTable
59
64
  tableCell.detailTextLabel.text = dataCell[:subtitle]
60
65
  end
61
66
 
67
+ tableCell.selectionStyle = UITableViewCellSelectionStyleNone if dataCell[:no_select]
62
68
 
63
69
  if dataCell[:image]
64
70
  tableCell.imageView.layer.masksToBounds = true
@@ -66,16 +72,30 @@ module ProMotion::MotionTable
66
72
  tableCell.imageView.layer.cornerRadius = dataCell[:image][:radius] if dataCell[:image][:radius]
67
73
  end
68
74
 
75
+ if dataCell[:subViews]
76
+ dataCell[:subViews].each do |view|
77
+ tableCell.addSubview view
78
+ end
79
+ end
80
+
81
+ if dataCell[:details]
82
+ tableCell.addSubview dataCell[:details][:image]
83
+ end
84
+
69
85
  tableCell.text = dataCell[:title]
70
86
  return tableCell
71
87
  end
72
88
 
73
89
  def sectionAtIndex(index)
74
- @mt_table_view_groups.at(index)
90
+ if @mt_filtered && tableView == self.tableView
91
+ @mt_filtered_data.at(index)
92
+ else
93
+ @mt_table_view_groups.at(index)
94
+ end
75
95
  end
76
96
 
77
97
  def cellAtSectionAndIndex(section, index)
78
- return sectionAtIndex(section)[:cells].at(index)
98
+ return sectionAtIndex(section)[:cells].at(index) if sectionAtIndex(section) && sectionAtIndex(section)[:cells]
79
99
  end
80
100
 
81
101
  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
@@ -90,7 +110,7 @@ module ProMotion::MotionTable
90
110
 
91
111
  dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
92
112
  dataCell[:arguments] = {} unless dataCell[:arguments]
93
- dataCell[:arguments][:value] = switch.isOn
113
+ dataCell[:arguments][:value] = switch.isOn if dataCell[:arguments].is_a? Hash
94
114
 
95
115
  triggerAction(dataCell[:accessoryAction], dataCell[:arguments]) if dataCell[:accessoryAction]
96
116
 
@@ -101,7 +121,7 @@ module ProMotion::MotionTable
101
121
  expectedArguments = self.method(action).arity
102
122
  if expectedArguments == 0
103
123
  self.send(action)
104
- elsif expectedArguments == 1
124
+ elsif expectedArguments == 1 || expectedArguments == -1
105
125
  self.send(action, arguments)
106
126
  else
107
127
  MotionTable::Console.log("MotionTable warning: #{action} expects #{expectedArguments} arguments. Maximum number of required arguments for an action is 1.", withColor: MotionTable::Console::RED_COLOR)
@@ -1,3 +1,3 @@
1
1
  module ProMotion
2
- VERSION = "0.1.2" unless defined?(ProMotion::VERSION)
2
+ VERSION = "0.2.0" unless defined?(ProMotion::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-12 00:00:00.000000000 Z
14
+ date: 2012-09-22 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: ProMotion is a new way to organize RubyMotion apps.
17
17
  email:
@@ -20,6 +20,9 @@ executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
+ - .c9revisions/lib/ProMotion.rb.c9save
24
+ - .c9revisions/lib/ProMotion/AppDelegate.rb.c9save
25
+ - .c9revisions/lib/ProMotion/classes/Screen.rb.c9save
23
26
  - .gitignore
24
27
  - Gemfile
25
28
  - LICENSE