ProMotion 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -18,5 +18,6 @@ tmp
18
18
  .repl_history
19
19
  build
20
20
  build/*
21
- *.000
22
- .rvmrc
21
+ .*.0??
22
+ .rvmrc
23
+ .DS_Store
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # ProMotion - A new way to organize RubyMotion apps.
1
+ # ProMotion - A new way to easily build RubyMotion apps.
2
2
 
3
3
  ProMotion introduces a new object called "Screens". Screens have a one-to-one relationship
4
- with your app's screens and can (usually) take the place of view controllers.
4
+ with your app's designed screens.
5
+
6
+ Check out the tutorial here: http://www.clearsightstudio.com/insights/ruby-motion-promotion-tutorial
7
+
8
+ Sample app here: https://github.com/jamonholmgren/promotion-tutorial
5
9
 
6
10
  Typical app file structure:
7
11
 
@@ -14,7 +18,6 @@ Typical app file structure:
14
18
  home_screen.rb
15
19
  settings_screen.rb
16
20
  models/
17
- view_controllers/
18
21
  views/
19
22
  app_delegate.rb
20
23
 
@@ -25,7 +28,7 @@ Loading your home screen:
25
28
  ```ruby
26
29
  # In /app/app_delegate.rb (note that AppDelegate extends ProMotion::AppDelegateParent)
27
30
  class AppDelegate < ProMotion::AppDelegateParent
28
- def on_load(options)
31
+ def on_load(app, options)
29
32
  open_screen MyHomeScreen.new(nav_bar: true)
30
33
  end
31
34
  end
@@ -51,14 +54,28 @@ class HomeScreen < ProMotion::Screen
51
54
  end
52
55
  ```
53
56
 
54
- Creating a tabbed bar:
57
+ Creating a tabbed bar from a screen (this has to be done inside a screen -- it won't work
58
+ in your app_delegate.rb). This will set the tab bar as the root view controller for your app,
59
+ so keep that in mind.
60
+
61
+ NOTE: It needs to be done in the on_appear or afterward, not the `on_load` or
62
+ `will_appear`. We will likely fix this in the future, but for now that's a restriction.
55
63
 
56
64
  ```ruby
57
- def on_load(options)
58
- @home = MyHomeScreen.new(nav_bar: true)
59
- @settings = SettingsScreen.new
60
- @contact = ContactScreen.new(nav_bar: true)
61
- open_tab_bar @home, @settings, @contact
65
+ def on_appear
66
+ @home ||= MyHomeScreen.new(nav_bar: true)
67
+ @settings ||= SettingsScreen.new
68
+ @contact ||= ContactScreen.new(nav_bar: true)
69
+ @tab_bar ||= open_tab_bar @home, @settings, @contact
70
+ end
71
+ ```
72
+
73
+ For each screen that belongs to the tab bar, you need to set the tab name and icon in the files.
74
+ In this example, we would need add the following to the three files (my_home_screen.rb, settings_screen.rb, contact_screen.rb):
75
+
76
+ ```ruby
77
+ def on_opened
78
+ set_tab_bar_item title: "Tab Name Goes Here", icon: "tab_icon.png" # in resources folder
62
79
  end
63
80
  ```
64
81
 
@@ -169,7 +186,7 @@ it to the current view. Screens include this helper by default.
169
186
 
170
187
  You can create sectioned table screens easily. TableScreen, SectionedTableScreen, GroupedTableScreen.
171
188
  This is loosely based on [motion-table](https://github.com/clearsightstudio/motion-table) (there are a
172
- few minor differences).
189
+ few minor differences). We will eventually combine the two.
173
190
 
174
191
  ```ruby
175
192
  class SettingsScreen < ProMotion::GroupedTableScreen
@@ -211,6 +228,18 @@ class SettingsScreen < ProMotion::GroupedTableScreen
211
228
  end
212
229
  ```
213
230
 
231
+ You can provide remotely downloaded images for cells by including the CocoaPod "SDWebImage" in
232
+ your Rakefile and doing this:
233
+
234
+ ```ruby
235
+ cells: [
236
+ {
237
+ title: "Cell with image",
238
+ remoteImage: { url: "http://placekitten.com/200/300", placeholder: "some-local-image" }
239
+ }
240
+ ]
241
+ ```
242
+
214
243
  # Reference
215
244
  (not comprehensive yet...working on this)
216
245
 
@@ -1,5 +1,5 @@
1
1
  class AppDelegate < ProMotion::AppDelegateParent
2
- def on_load(options)
2
+ def on_load(app, options)
3
3
  open_screen TestScreen, nav_bar: true
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ module ProMotion
6
6
  return true if RUBYMOTION_ENV == "test"
7
7
 
8
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
-
10
- on_load launchOptions
9
+
10
+ on_load(application, launchOptions)
11
11
 
12
12
  open_home_screen if has_home_screen
13
13
 
@@ -1,5 +1,7 @@
1
1
  module ProMotion
2
2
  class NavigationController < UINavigationController
3
-
3
+ def dealloc
4
+ $stderr.puts "Deallocating #{self.to_s}" if ProMotion::Screen.debug_mode
5
+ end
4
6
  end
5
7
  end
@@ -0,0 +1,16 @@
1
+ module ProMotion
2
+ class TableViewCell < UITableViewCell
3
+ attr_accessor :image_size
4
+
5
+ def layoutSubviews
6
+ super
7
+
8
+ if self.image_size && self.imageView.image && self.imageView.image.size && self.imageView.image.size.width > 0
9
+ f = self.imageView.frame
10
+ size_inset_x = (self.imageView.size.width - self.image_size) / 2
11
+ size_inset_y = (self.imageView.size.height - self.image_size) / 2
12
+ self.imageView.frame = CGRectInset(f, size_inset_x, size_inset_y)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -16,6 +16,39 @@ module ProMotion
16
16
  super
17
17
  self.screen.view_did_appear(animated) if self.screen && self.screen.respond_to?(:view_did_appear)
18
18
  end
19
+
20
+ def viewWillDisappear(animated)
21
+ if self.screen && self.screen.respond_to?(:view_will_disappear)
22
+ self.screen.view_will_disappear(animated)
23
+ end
24
+ super
25
+ end
26
+
27
+ def viewDidDisappear(animated)
28
+ if self.screen && self.screen.respond_to?(:view_did_disappear)
29
+ self.screen.view_did_disappear(animated)
30
+ end
31
+ super
32
+ end
33
+
34
+ def shouldAutorotateToInterfaceOrientation(orientation)
35
+ self.screen.should_rotate(orientation)
36
+ end
37
+
38
+ def shouldAutorotate
39
+ self.screen.should_autorotate
40
+ end
41
+
42
+ def willRotateToInterfaceOrientation(orientation, duration:duration)
43
+ self.screen.will_rotate(orientation, duration)
44
+ end
45
+
46
+ def didRotateFromInterfaceOrientation(orientation)
47
+ self.screen.on_rotate
48
+ end
19
49
 
50
+ def dealloc
51
+ $stderr.puts "Deallocating #{self.to_s}" if ProMotion::Screen.debug_mode
52
+ end
20
53
  end
21
54
  end
@@ -4,18 +4,65 @@ module ProMotion
4
4
 
5
5
  def viewDidLoad
6
6
  super
7
- self.screen.view_did_load if self.screen && self.screen.respond_to?(:view_did_load)
7
+ if screen_will_respond_to?(:view_did_load)
8
+ self.screen.view_did_load
9
+ end
8
10
  end
9
11
 
10
12
  def viewWillAppear(animated)
11
13
  super
12
- self.screen.view_will_appear(animated) if self.screen && self.screen.respond_to?(:view_will_appear)
14
+ if screen_will_respond_to?(:view_will_appear)
15
+ self.screen.view_will_appear(animated)
16
+ end
13
17
  end
14
18
 
15
19
  def viewDidAppear(animated)
16
20
  super
17
- self.screen.view_did_appear(animated) if self.screen && self.screen.respond_to?(:view_did_appear)
21
+ if screen_will_respond_to?(:view_did_appear)
22
+ self.screen.view_did_appear(animated)
23
+ end
18
24
  end
19
25
 
26
+ def viewWillDisappear(animated)
27
+ if screen_will_respond_to?(:view_will_disappear)
28
+ self.screen.view_will_disappear(animated)
29
+ end
30
+ super
31
+ end
32
+
33
+ def viewDidDisappear(animated)
34
+ if screen_will_respond_to?(:view_did_disappear)
35
+ self.screen.view_did_disappear(animated)
36
+ end
37
+ super
38
+ end
39
+
40
+ def screen_will_respond_to?(method)
41
+ self.screen && self.screen.respond_to?(method)
42
+ end
43
+
44
+ def shouldAutorotateToInterfaceOrientation(orientation)
45
+ self.screen.should_rotate(orientation)
46
+ end
47
+
48
+ def shouldAutorotate
49
+ self.screen.should_autorotate
50
+ end
51
+
52
+ def supportedInterfaceOrientations
53
+ self.screen.supported_orientations
54
+ end
55
+
56
+ def willRotateToInterfaceOrientation(orientation, duration:duration)
57
+ self.screen.will_rotate(orientation, duration)
58
+ end
59
+
60
+ def didRotateFromInterfaceOrientation(orientation)
61
+ self.screen.on_rotate
62
+ end
63
+
64
+ def dealloc
65
+ $stderr.puts "Deallocating #{self.to_s}" if ProMotion::Screen.debug_mode
66
+ end
20
67
  end
21
68
  end
@@ -24,14 +24,16 @@ module ProMotion
24
24
  self.view_controller.presentModalViewController(screen.main_controller, animated:true)
25
25
  elsif args[:in_tab] && self.tab_bar
26
26
  vc = open_tab(args[:in_tab])
27
- $stderr.puts "Found a #{vc.to_s}"
27
+ # $stderr.puts "Found a #{vc.to_s}"
28
28
  if vc
29
- if vc.is_a? UINavigationController
29
+ if vc.is_a?(UINavigationController)
30
+ screen.navigation_controller = vc
30
31
  push_view_controller(screen.view_controller, vc)
31
32
  else
32
33
  self.tab_bar.selectedIndex = vc.tabBarItem.tag
33
34
  $stderr.puts "#{self.tab_bar.selectedIndex} is selected and should be #{vc.tabBarItem.tag}"
34
35
  # PM::TabBar.replace_current_item(self.tab_bar, view_controller: screen.view_controller)
36
+ # TODO: This doesn't work yet.
35
37
  end
36
38
  else
37
39
  $stderr.puts "No tab bar item '#{args[:in_tab]}'"
@@ -41,7 +43,7 @@ module ProMotion
41
43
  else
42
44
  open_view_controller screen.main_controller
43
45
  end
44
-
46
+
45
47
  if screen.respond_to?(:on_opened)
46
48
  screen.send(:on_opened)
47
49
  end
@@ -72,8 +74,14 @@ module ProMotion
72
74
  else
73
75
  Console.log("Tried to close #{self.to_s}; however, this screen isn't modal or in a nav bar.", withColor: Console::PURPLE_COLOR)
74
76
  end
75
-
76
- previous_screen.send(:on_return, args) if previous_screen && previous_screen.respond_to?(:on_return)
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
77
85
  end
78
86
 
79
87
  def tab_bar_controller(*screens)
@@ -121,7 +129,6 @@ module ProMotion
121
129
 
122
130
  def open_tab(tab)
123
131
  if tab.is_a? String
124
- $stderr.puts "Opening tab in #{self.tab_bar.to_s} : #{tab}"
125
132
  return PM::TabBar.select(self.tab_bar, title: tab)
126
133
  else
127
134
  $stderr.puts "Unable to open tab #{tab.to_s} because it isn't a string."
@@ -3,12 +3,13 @@ module ProMotion
3
3
  class Screen
4
4
  include ProMotion::ScreenNavigation
5
5
  include ProMotion::ScreenElements
6
+ include ProMotion::SystemHelper
6
7
 
7
8
  attr_accessor :view_controller, :navigation_controller, :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
8
9
 
9
10
  def initialize(args = {})
10
11
  args.each do |k, v|
11
- self.send "#{k}=", v if self.respond_to?("#{k}=")
12
+ self.send("#{k}=", v) if self.respond_to?("#{k}=")
12
13
  end
13
14
  self.load_view_controller
14
15
  self.view_controller.title = self.title
@@ -86,21 +87,38 @@ module ProMotion
86
87
  self.view_controller = vc
87
88
  end
88
89
 
90
+ def view_did_load; end
91
+ def on_opened; end
92
+
89
93
  def view_will_appear(animated)
90
- self.will_appear if self.respond_to?(:will_appear)
94
+ ProMotion::Screen.current_screen = self
95
+ self.will_appear
91
96
  end
97
+ def will_appear; end
92
98
 
93
99
  def view_did_appear(animated)
94
- self.on_appear if self.respond_to?(:on_appear)
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
95
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
96
114
 
97
115
  def title
98
- self.class.send :get_title
116
+ self.class.send(:get_title)
99
117
  end
100
118
 
101
119
  def title=(new_title)
102
120
  self.class.title = new_title
103
- self.view_controller.title = new_title
121
+ self.view_controller.title = new_title if self.view_controller
104
122
  end
105
123
 
106
124
  def main_controller
@@ -108,11 +126,72 @@ module ProMotion
108
126
  self.view_controller
109
127
  end
110
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
111
174
  end
112
175
 
113
176
  # Class methods
114
177
  class Screen
115
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
+
116
195
  def title(t)
117
196
  @title = t
118
197
  end
@@ -4,7 +4,6 @@ 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
7
  next if sub_view.isHidden
9
8
  y = sub_view.frame.origin.y
10
9
  h = sub_view.frame.size.height
@@ -1,34 +1,6 @@
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
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]
11
-
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
-
29
-
30
-
31
-
32
4
  def create_tab_bar_controller_from_data(data)
33
5
  data = self.setTags(data)
34
6
 
@@ -27,32 +27,51 @@ module ProMotion::MotionTable
27
27
 
28
28
  # Number of cells
29
29
  def tableView(tableView, numberOfRowsInSection:section)
30
- return sectionAtIndex(section)[:cells].length if sectionAtIndex(section)
30
+ return sectionAtIndex(section)[:cells].length if sectionAtIndex(section) && sectionAtIndex(section)[:cells]
31
31
  0
32
32
  end
33
33
 
34
34
  def tableView(tableView, titleForHeaderInSection:section)
35
- return sectionAtIndex(section)[:title] if sectionAtIndex(section)
35
+ return sectionAtIndex(section)[:title] if sectionAtIndex(section) && sectionAtIndex(section)[:title]
36
36
  end
37
37
 
38
38
  # Set table_data_index if you want the right hand index column (jumplist)
39
39
  def sectionIndexTitlesForTableView(tableView)
40
- self.table_data_index if respond_to?(:table_data_index)
40
+ if self.respond_to?(:table_data_index)
41
+ self.table_data_index
42
+ end
41
43
  end
42
44
 
43
45
  def tableView(tableView, cellForRowAtIndexPath:indexPath)
46
+ # Aah, magic happens here...
47
+
44
48
  dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
49
+ return UITableViewCell.alloc.init unless dataCell
45
50
  dataCell[:cellStyle] ||= UITableViewCellStyleDefault
46
-
47
- cellIdentifier = "Cell"
51
+ dataCell[:cellIdentifier] ||= "Cell"
52
+ cellIdentifier = dataCell[:cellIdentifier]
53
+ dataCell[:cellClass] ||= PM::TableViewCell
48
54
 
49
55
  tableCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
50
56
  unless tableCell
51
- tableCell = UITableViewCell.alloc.initWithStyle(dataCell[:cellStyle], reuseIdentifier:cellIdentifier)
57
+ tableCell = dataCell[:cellClass].alloc.initWithStyle(dataCell[:cellStyle], reuseIdentifier:cellIdentifier)
58
+
59
+ # Add optimizations here
60
+ tableCell.layer.masksToBounds = true if dataCell[:masksToBounds]
61
+ tableCell.backgroundColor = dataCell[:backgroundColor] if dataCell[:backgroundColor]
62
+ tableCell.selectionStyle = dataCell[:selectionStyle] if dataCell[:selectionStyle]
63
+ tableCell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
64
+ end
65
+
66
+ if dataCell[:cellClassAttributes]
67
+ set_cell_attributes tableCell, dataCell[:cellClassAttributes]
68
+ end
69
+
70
+ if dataCell[:accessoryView]
71
+ tableCell.accessoryView = dataCell[:accessoryView]
72
+ tableCell.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth
52
73
  end
53
74
 
54
- tableCell.accessoryView = dataCell[:accessoryView] if dataCell[:accessoryView]
55
-
56
75
  if dataCell[:accessory] && dataCell[:accessory] == :switch
57
76
  switchView = UISwitch.alloc.initWithFrame(CGRectZero)
58
77
  switchView.addTarget(self, action: "accessoryToggledSwitch:", forControlEvents:UIControlEventValueChanged);
@@ -62,19 +81,44 @@ module ProMotion::MotionTable
62
81
 
63
82
  if dataCell[:subtitle]
64
83
  tableCell.detailTextLabel.text = dataCell[:subtitle]
84
+ tableCell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth
65
85
  end
66
86
 
67
87
  tableCell.selectionStyle = UITableViewCellSelectionStyleNone if dataCell[:no_select]
68
88
 
69
- if dataCell[:image]
89
+ if dataCell[:remoteImage]
90
+ if tableCell.imageView.respond_to?("setImageWithURL:placeholderImage:")
91
+ url = dataCell[:remoteImage][:url]
92
+ url = NSURL.URLWithString(url) unless url.is_a?(NSURL)
93
+ placeholder = dataCell[:remoteImage][:placeholder]
94
+ placeholder = UIImage.imageNamed(placeholder) if placeholder.is_a?(String)
95
+
96
+ tableCell.image_size = dataCell[:remoteImage][:size] if dataCell[:remoteImage][:size] && tableCell.respond_to?("image_size=")
97
+ tableCell.imageView.setImageWithURL(url, placeholderImage: placeholder)
98
+ tableCell.imageView.layer.masksToBounds = true
99
+ tableCell.imageView.layer.cornerRadius = dataCell[:remoteImage][:radius]
100
+ else
101
+ ProMotion::MotionTable::Console.log("ProMotion Warning: to use remoteImage with TableScreen you need to include the CocoaPod 'SDWebImage'.", withColor: MotionTable::Console::RED_COLOR)
102
+ end
103
+ elsif dataCell[:image]
70
104
  tableCell.imageView.layer.masksToBounds = true
71
105
  tableCell.imageView.image = dataCell[:image][:image]
72
106
  tableCell.imageView.layer.cornerRadius = dataCell[:image][:radius] if dataCell[:image][:radius]
73
107
  end
74
108
 
75
109
  if dataCell[:subViews]
110
+ tag_number = 0
76
111
  dataCell[:subViews].each do |view|
77
- tableCell.addSubview view
112
+ # Remove an existing view at that tag number
113
+ tag_number += 1
114
+ existing_view = tableCell.viewWithTag(tag_number)
115
+ existing_view.removeFromSuperview if existing_view
116
+
117
+ # Add the subview if it exists
118
+ if view
119
+ view.tag = tag_number
120
+ tableCell.addSubview view
121
+ end
78
122
  end
79
123
  end
80
124
 
@@ -82,12 +126,33 @@ module ProMotion::MotionTable
82
126
  tableCell.addSubview dataCell[:details][:image]
83
127
  end
84
128
 
85
- tableCell.text = dataCell[:title]
129
+ if dataCell[:styles] && dataCell[:styles][:textLabel] && dataCell[:styles][:textLabel][:frame]
130
+ ui_label = false
131
+ tableCell.contentView.subviews.each do |view|
132
+ if view.is_a? UILabel
133
+ ui_label = true
134
+ view.text = dataCell[:styles][:textLabel][:text]
135
+ end
136
+ end
137
+
138
+ unless ui_label == true
139
+ label ||= UILabel.alloc.initWithFrame(CGRectZero)
140
+ set_cell_attributes label, dataCell[:styles][:textLabel]
141
+ tableCell.contentView.addSubview label
142
+ end
143
+ # hackery
144
+ tableCell.textLabel.textColor = UIColor.clearColor
145
+ else
146
+ cell_title = dataCell[:title]
147
+ cell_title ||= ""
148
+ tableCell.textLabel.text = cell_title
149
+ end
150
+
86
151
  return tableCell
87
152
  end
88
153
 
89
154
  def sectionAtIndex(index)
90
- if @mt_filtered && tableView == self.tableView
155
+ if @mt_filtered
91
156
  @mt_filtered_data.at(index)
92
157
  else
93
158
  @mt_table_view_groups.at(index)
@@ -101,6 +166,8 @@ module ProMotion::MotionTable
101
166
  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
102
167
  cell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
103
168
  tableView.deselectRowAtIndexPath(indexPath, animated: true);
169
+ cell[:arguments] ||= {}
170
+ cell[:arguments][:cell] = cell if cell[:arguments].is_a?(Hash)
104
171
  triggerAction(cell[:action], cell[:arguments]) if cell[:action]
105
172
  end
106
173
 
@@ -124,12 +191,29 @@ module ProMotion::MotionTable
124
191
  elsif expectedArguments == 1 || expectedArguments == -1
125
192
  self.send(action, arguments)
126
193
  else
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)
194
+ ProMotion::MotionTable::Console.log("MotionTable warning: #{action} expects #{expectedArguments} arguments. Maximum number of required arguments for an action is 1.", withColor: MotionTable::Console::RED_COLOR)
128
195
  end
129
196
  else
130
- MotionTable::Console.log(self, actionNotImplemented: action)
197
+ ProMotion::MotionTable::Console.log(self, actionNotImplemented: action)
131
198
  end
132
199
  end
133
-
200
+
201
+ def set_cell_attributes(element, args = {})
202
+ args.each do |k, v|
203
+ if v.is_a? Hash
204
+ v.each do
205
+ sub_element = element.send("#{k}")
206
+ set_cell_attributes(sub_element, v)
207
+ end
208
+ # v.each do |k2, v2|
209
+ # sub_element = element.send("#{k}")
210
+ # sub_element.send("#{k2}=", v2) if sub_element.respond_to?("#{k2}=")
211
+ # end
212
+ else
213
+ element.send("#{k}=", v) if element.respond_to?("#{k}=")
214
+ end
215
+ end
216
+ element
217
+ end
134
218
  end
135
219
  end
@@ -0,0 +1,29 @@
1
+ module ProMotion
2
+ module SystemHelper
3
+ module_function
4
+
5
+ def ios_version
6
+ UIDevice.currentDevice.systemVersion
7
+ end
8
+
9
+ def ios_version_is?(version)
10
+ ios_version == version
11
+ end
12
+
13
+ def ios_version_greater?(version)
14
+ ios_version > version
15
+ end
16
+
17
+ def ios_version_greater_eq?(version)
18
+ ios_version >= version
19
+ end
20
+
21
+ def ios_version_less?(version)
22
+ ios_version < version
23
+ end
24
+
25
+ def ios_version_less_eq?(version)
26
+ ios_version <= version
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ProMotion
2
- VERSION = "0.2.0" unless defined?(ProMotion::VERSION)
2
+ VERSION = "0.3.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.2.0
4
+ version: 0.3.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-22 00:00:00.000000000 Z
14
+ date: 2012-12-03 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: ProMotion is a new way to organize RubyMotion apps.
17
17
  email:
@@ -38,6 +38,7 @@ files:
38
38
  - lib/ProMotion/Console.rb
39
39
  - lib/ProMotion/ProMotion.rb
40
40
  - lib/ProMotion/_ext/NavigationController.rb
41
+ - lib/ProMotion/_ext/TableViewCell.rb
41
42
  - lib/ProMotion/_ext/TableViewController.rb
42
43
  - lib/ProMotion/_ext/ViewController.rb
43
44
  - lib/ProMotion/_modules/ScreenElements.rb
@@ -54,6 +55,7 @@ files:
54
55
  - lib/ProMotion/helpers/motion-table/2nd/grouped_table.rb
55
56
  - lib/ProMotion/helpers/motion-table/2nd/plain_table.rb
56
57
  - lib/ProMotion/helpers/motion-table/console.rb
58
+ - lib/ProMotion/helpers/system_helper.rb
57
59
  - lib/ProMotion/version.rb
58
60
  homepage: https://github.com/clearsightstudio/ProMotion
59
61
  licenses: []