ProMotion-XLForm 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97b4f80e4bb25b2941de7eb3166ba566a8f1c0cc
4
- data.tar.gz: d69b0217a03e59a2a06ccd8726be9a4472e13f4f
3
+ metadata.gz: ee73f17572e76ecaba9208e0073c277f1cba8264
4
+ data.tar.gz: 168afe00cae3b0a2c3bba1edb902d084e5784870
5
5
  SHA512:
6
- metadata.gz: b950d047e9e13ea131797523c9aa4016531d88167df18315ed0fe0e9af9ce8263e648a057e80b0e3f3b59786cf9e95f1b5043937a3fa431a2af0624bb707a6a0
7
- data.tar.gz: f34aa52c706ecc217b24eb0bab024c7bd58f1e93e4838e330c70d71297dca4d91ec4469119ad6bb1a00112021be8196fb1a47b8e9babc4d73a91c22f9ca57d1a
6
+ metadata.gz: 26386689545a58da0f3d25dcdb545eede47d3ff0d1bdc5b73c64ab9d770f5c99f9c35c688ce4ef5912e0aa575be70b0987e53ef174979428c4bf044090d14e6b
7
+ data.tar.gz: cb0705340f010c00762022e185fffadcbb9916adadedb6d64c6332a3f78a1c4693f492790a3a5b8b1bc10a7496b663f64f95b2509bdb7cdc526e963185e7bdec
data/README.md CHANGED
@@ -125,7 +125,8 @@ end
125
125
 
126
126
  ### Getting values
127
127
 
128
- You can get the values of your form with `values`. You can also get validation errors with `validation_errors` and check if the form is valid with `valid?`
128
+ You can get the values of your form with `values`. You can also get validation errors with `validation_errors` and check if the form is valid with `valid?`.
129
+ You can also get a specific value with `value_for_cell(:my_cell)`.
129
130
 
130
131
  ### Events
131
132
 
@@ -217,6 +218,36 @@ end
217
218
 
218
219
  For a more advanced custom selector, you can set `view_controller_class:`. See [XLForm documentation](https://github.com/xmartlabs/XLForm/#custom-selectors---selector-row-with-a-custom-selector-view-controller) for more informations.
219
220
 
221
+ ### Cell
222
+
223
+ You can use your own cell by providing `cell_class`
224
+
225
+ ```ruby
226
+ {
227
+ title: 'MyCustomCell',
228
+ name: :custom_cell,
229
+ cell_class: MyCustomCell
230
+ }
231
+
232
+ class MyCustomCell < PM::XLFormCell
233
+ def initWithStyle(style, reuseIdentifier: reuse_identifier)
234
+ super.tap do
235
+ @label = UILabel.new
236
+ self.contentView.addSubview(@label)
237
+ end
238
+ end
239
+
240
+ def update
241
+ super
242
+
243
+ @label.text = value
244
+ @label.sizeToFit
245
+ end
246
+ end
247
+ ```
248
+
249
+ In your cell, you can set the value with `self.value=` and get the value with `self.value`
250
+
220
251
  ### Validators
221
252
 
222
253
  You can add validators to cells.
@@ -290,6 +321,20 @@ Finally, you can provide a PM::Validator with a `valid?(cell)` method.
290
321
  }
291
322
  ```
292
323
 
324
+ ### Buttons and click
325
+ You can add `:on_click` on `:button` which accepts 0 or 1 argument (the cell).
326
+ ```ruby
327
+ {
328
+ title: 'Click me',
329
+ name: :click_me,
330
+ type: :button,
331
+ on_click: -> (cell) {
332
+ mp "You clicked me"
333
+ }
334
+ }
335
+ ```
336
+
337
+
293
338
  ### Appearance
294
339
  You can change the appearance of the cell using the `appearance` hash
295
340
 
@@ -6,6 +6,7 @@ require 'motion-cocoapods'
6
6
 
7
7
  Motion::Project::App.setup do |app|
8
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
9
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_cell.rb")
9
10
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_image_selector_cell.rb")
10
11
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_color_selector_cell.rb")
11
12
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_class_methods.rb")
@@ -15,6 +16,9 @@ Motion::Project::App.setup do |app|
15
16
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_screen.rb")
16
17
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_sub_form_screen.rb")
17
18
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_patch.rb")
19
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_helper.rb")
20
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_cell_builder.rb")
21
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_section_builder.rb")
18
22
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/value_transformer.rb")
19
23
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/validator.rb")
20
24
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/url_validator.rb")
@@ -0,0 +1,12 @@
1
+ module ProMotion
2
+ class XLFormCell < XLFormBaseCell
3
+
4
+ def value=(value)
5
+ rowDescriptor.value = value
6
+ end
7
+
8
+ def value
9
+ rowDescriptor ? rowDescriptor.value : nil
10
+ end
11
+ end
12
+ end
@@ -19,10 +19,10 @@ class XLFormColorSelectorCell < XLFormBaseCell
19
19
  self.formViewController.view.endEditing(true)
20
20
 
21
21
  size = if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
22
- [400, 440]
23
- else
24
- [320, 440]
25
- end
22
+ [400, 440]
23
+ else
24
+ [320, 440]
25
+ end
26
26
  color_chooser = PMXLColorChooser.alloc.initWithFrame [[0, 0], size]
27
27
  color_chooser.delegate = self
28
28
  color_chooser.color = self.rowDescriptor.value || UIColor.whiteColor
@@ -34,9 +34,9 @@ class XLFormColorSelectorCell < XLFormBaseCell
34
34
  @popover.popoverContentSize = color_chooser.frame.size
35
35
  f = self.contentView.convertRect(@color_view.frame, toView: self.formViewController.view)
36
36
  @popover.presentPopoverFromRect(f,
37
- inView: self.formViewController.view,
37
+ inView: self.formViewController.view,
38
38
  permittedArrowDirections: UIPopoverArrowDirectionAny,
39
- animated: true)
39
+ animated: true)
40
40
  else
41
41
  controller = UIViewController.new
42
42
  controller.view = color_chooser
@@ -44,19 +44,19 @@ class XLFormColorSelectorCell < XLFormBaseCell
44
44
  navigation_controller = UINavigationController.alloc.initWithRootViewController(controller)
45
45
  navigation_controller.navigationBar.translucent = false
46
46
  right = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemDone,
47
- target: self,
48
- action: 'hide_picker:')
47
+ target: self,
48
+ action: 'hide_picker:')
49
49
  controller.navigationItem.rightBarButtonItem = right
50
50
  if self.formViewController.presentedViewController
51
51
  self.formViewController.dismissViewControllerAnimated(true,
52
- completion: -> {
53
- self.formViewController.presentViewController(navigation_controller,
54
- animated: true,
55
- completion: nil)
56
- })
52
+ completion: -> {
53
+ self.formViewController.presentViewController(navigation_controller,
54
+ animated: true,
55
+ completion: nil)
56
+ })
57
57
  else
58
58
  self.formViewController.presentViewController(navigation_controller,
59
- animated: true,
59
+ animated: true,
60
60
  completion: nil)
61
61
  end
62
62
  end
@@ -69,7 +69,7 @@ class XLFormColorSelectorCell < XLFormBaseCell
69
69
 
70
70
  def update
71
71
  super.tap do
72
- self.textLabel.text = (self.rowDescriptor.isRequired and self.rowDescriptor.title) ? "#{self.rowDescriptor.title}*" : self.rowDescriptor.title
72
+ self.textLabel.text = (self.rowDescriptor.isRequired && self.rowDescriptor.title) ? "#{self.rowDescriptor.title}*" : self.rowDescriptor.title
73
73
  @color_view.frame = [[305.0, 7.0], [80.0, 30.0]]
74
74
  color = self.rowDescriptor.value
75
75
  unless color
@@ -148,8 +148,8 @@ class PMXLBrightnessSlider < UISlider
148
148
  self.userInteractionEnabled = true
149
149
 
150
150
  self.addTarget(self,
151
- action: 'slider_value_changed:',
152
- forControlEvents: UIControlEventValueChanged)
151
+ action: 'slider_value_changed:',
152
+ forControlEvents: UIControlEventValueChanged)
153
153
  end
154
154
 
155
155
  def slider_value_changed(_)
@@ -4,11 +4,11 @@ class XLFormImageSelectorCell < XLFormBaseCell
4
4
 
5
5
  def configure
6
6
  super
7
- @image_height = 100.0
8
- @image_width = 100.0
9
- self.selectionStyle = UITableViewCellSelectionStyleNone
7
+ @image_height = 100.0
8
+ @image_width = 100.0
9
+ self.selectionStyle = UITableViewCellSelectionStyleNone
10
10
  self.backgroundColor = UIColor.whiteColor
11
- self.separatorInset = UIEdgeInsetsZero
11
+ self.separatorInset = UIEdgeInsetsZero
12
12
 
13
13
  self.contentView.addSubview(imageview)
14
14
  self.contentView.addSubview(text_label)
@@ -29,52 +29,53 @@ class XLFormImageSelectorCell < XLFormBaseCell
29
29
  end
30
30
 
31
31
  def formDescriptorCellDidSelectedWithFormController(controller)
32
- if NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1
32
+ if Kernel.const_defined?("UIAlertController")
33
33
  alert = UIAlertController.alertControllerWithTitle(self.rowDescriptor.selectorTitle,
34
- message: nil,
34
+ message: nil,
35
35
  preferredStyle: UIAlertControllerStyleActionSheet)
36
36
 
37
37
  alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Choose From Library", nil),
38
- style: UIAlertActionStyleDefault,
38
+ style: UIAlertActionStyleDefault,
39
39
  handler: lambda { |_|
40
- self.formViewController.dismissViewControllerAnimated(true,
41
- completion: -> {
42
- open_picker(UIImagePickerControllerSourceTypePhotoLibrary)
43
- })
40
+ open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
44
41
  }))
45
42
 
46
43
  if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
47
44
  alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Take Photo", nil),
48
- style: UIAlertActionStyleDefault,
45
+ style: UIAlertActionStyleDefault,
49
46
  handler: lambda { |_|
50
- self.formViewController.dismissViewControllerAnimated(true,
51
- completion: -> {
52
- open_picker(UIImagePickerControllerSourceTypeCamera)
53
- })
47
+ open_from_alert(UIImagePickerControllerSourceTypeCamera)
54
48
  }))
55
49
  end
50
+
51
+ if
52
+ alert.modalPresentationStyle = UIModalPresentationPopover
53
+ alert.popoverPresentationController.sourceView = self.contentView
54
+ alert.popoverPresentationController.sourceRect = self.contentView.bounds
55
+ end
56
+
57
+ present = -> {
58
+ self.formViewController.presentViewController(alert, animated: true, completion: nil)
59
+ }
56
60
  if self.formViewController.presentedViewController
57
- self.formViewController.dismissViewControllerAnimated(true,
58
- completion: -> {
59
- self.formViewController.presentViewController(alert, animated: true, completion: nil)
60
- })
61
+ self.formViewController.dismissViewControllerAnimated(true, completion: present)
61
62
  else
62
- self.formViewController.presentViewController(alert, animated: true, completion: nil)
63
+ present.call
63
64
  end
64
65
 
65
66
  else
66
67
  if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
67
68
  action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
68
- delegate: self,
69
- cancelButtonTitle: NSLocalizedString("Cancel", nil),
69
+ delegate: self,
70
+ cancelButtonTitle: NSLocalizedString("Cancel", nil),
70
71
  destructiveButtonTitle: nil,
71
- otherButtonTitles: NSLocalizedString("Choose From Library", nil), NSLocalizedString("Take Photo", nil), nil)
72
+ otherButtonTitles: NSLocalizedString("Choose From Library", nil), NSLocalizedString("Take Photo", nil), nil)
72
73
  else
73
74
  action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
74
- delegate: self,
75
- cancelButtonTitle: NSLocalizedString("Cancel", nil),
75
+ delegate: self,
76
+ cancelButtonTitle: NSLocalizedString("Cancel", nil),
76
77
  destructiveButtonTitle: nil,
77
- otherButtonTitles: NSLocalizedString("Choose From Library", nil), nil)
78
+ otherButtonTitles: NSLocalizedString("Choose From Library", nil), nil)
78
79
  end
79
80
  action_sheet.tag = self.tag
80
81
  action_sheet.showInView(self.formViewController.view)
@@ -88,29 +89,29 @@ class XLFormImageSelectorCell < XLFormBaseCell
88
89
  self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-6-[text]", options: 0, metrics: 0, views: ui_components))
89
90
 
90
91
  self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
91
- attribute: NSLayoutAttributeTop,
92
- relatedBy: NSLayoutRelationEqual,
93
- toItem: self.contentView,
94
- attribute: NSLayoutAttributeTop,
92
+ attribute: NSLayoutAttributeTop,
93
+ relatedBy: NSLayoutRelationEqual,
94
+ toItem: self.contentView,
95
+ attribute: NSLayoutAttributeTop,
95
96
  multiplier: 1.0,
96
- constant: 10.0))
97
+ constant: 10.0))
97
98
 
98
99
  self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
99
- attribute: NSLayoutAttributeBottom,
100
- relatedBy: NSLayoutRelationEqual,
101
- toItem: self.contentView,
102
- attribute: NSLayoutAttributeBottom,
100
+ attribute: NSLayoutAttributeBottom,
101
+ relatedBy: NSLayoutRelationEqual,
102
+ toItem: self.contentView,
103
+ attribute: NSLayoutAttributeBottom,
103
104
  multiplier: 1.0,
104
- constant: -10.0))
105
+ constant: -10.0))
105
106
 
106
107
  self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[image(width)]", options: 0, metrics: { "width" => @image_width }, views: ui_components))
107
108
  self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
108
- attribute: NSLayoutAttributeCenterX,
109
- relatedBy: NSLayoutRelationEqual,
110
- toItem: self.contentView,
111
- attribute: NSLayoutAttributeCenterX,
109
+ attribute: NSLayoutAttributeCenterX,
110
+ relatedBy: NSLayoutRelationEqual,
111
+ toItem: self.contentView,
112
+ attribute: NSLayoutAttributeCenterX,
112
113
  multiplier: 1.0,
113
- constant: 0.0))
114
+ constant: 0.0))
114
115
  super
115
116
  end
116
117
 
@@ -121,15 +122,15 @@ class XLFormImageSelectorCell < XLFormBaseCell
121
122
 
122
123
  def setImageValue(image)
123
124
  self.rowDescriptor.value = image
124
- imageview.image = image
125
+ imageview.image = image
125
126
  end
126
127
 
127
128
  def observeValueForKeyPath(key_path, ofObject: object, change: change, context: _)
128
129
  if object == text_label && key_path == "text"
129
130
  if change[NSKeyValueChangeKindKey] == NSKeyValueChangeSetting
130
131
  text_label.sizeToFit
131
- frame = text_label.frame
132
- frame.origin = [16, 4]
132
+ frame = text_label.frame
133
+ frame.origin = [16, 4]
133
134
  text_label.frame = frame
134
135
  self.contentView.needsUpdateConstraints
135
136
  end
@@ -148,50 +149,51 @@ class XLFormImageSelectorCell < XLFormBaseCell
148
149
 
149
150
  case title
150
151
  when NSLocalizedString("Choose From Library", nil)
151
- open_picker(UIImagePickerControllerSourceTypePhotoLibrary)
152
+ open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
152
153
  when NSLocalizedString("Take Photo", nil)
153
- open_picker(UIImagePickerControllerSourceTypeCamera)
154
+ open_from_alert(UIImagePickerControllerSourceTypeCamera)
154
155
  else
155
156
  return
156
157
  end
157
158
  end
158
159
 
160
+ def open_from_alert(source)
161
+ open = -> {
162
+ open_picker(source)
163
+ }
164
+
165
+ if @popover_controller && @popover_controller.isPopoverVisible
166
+ @popover_controller.dismissPopoverAnimated(true)
167
+ open.call
168
+ elsif self.formViewController.presentedViewController
169
+ self.formViewController.dismissViewControllerAnimated(true, completion: open)
170
+ else
171
+ open.call
172
+ end
173
+ end
174
+
159
175
  def open_picker(source)
160
- image_picker = UIImagePickerController.alloc.init
161
- image_picker.delegate = self
162
- image_picker.allowsEditing = true
163
- image_picker.sourceType = source
176
+ @image_picker = UIImagePickerController.alloc.init
177
+ @image_picker.delegate = self
178
+ @image_picker.allowsEditing = true
179
+ @image_picker.sourceType = source
164
180
 
165
181
  if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
166
- if @popover_controller && @popover_controller.isPopoverVisible
167
- @popover_controller.dismissPopoverAnimated(true)
168
- end
169
- @popover_controller = UIPopoverController.alloc.initWithContentViewController(image_picker)
170
- Dispatch::Queue.main.async do
171
- @popover_controller.presentPopoverFromRect(self.contentView.frame,
172
- inView: self.formViewController.view,
173
- permittedArrowDirections: UIPopoverArrowDirectionAny,
174
- animated: true)
175
- end
182
+ @popover_controller = UIPopoverController.alloc.initWithContentViewController(@image_picker)
183
+ @popover_controller.presentPopoverFromRect(self.contentView.frame,
184
+ inView: self.formViewController.view,
185
+ permittedArrowDirections: UIPopoverArrowDirectionAny,
186
+ animated: true)
176
187
  else
177
- if self.formViewController.presentedViewController
178
- self.formViewController.dismissViewControllerAnimated(true,
179
- completion: -> {
180
- self.formViewController.presentViewController(image_picker,
181
- animated: true,
182
- completion: nil)
183
- })
184
- else
185
- self.formViewController.presentViewController(image_picker,
186
- animated: true,
187
- completion: nil)
188
- end
188
+ self.formViewController.presentViewController(@image_picker,
189
+ animated: true,
190
+ completion: nil)
189
191
  end
190
192
  end
191
193
 
192
194
  # UIImagePickerControllerDelegate
193
195
  def imagePickerController(_, didFinishPickingMediaWithInfo: info)
194
- editedImage = info[UIImagePickerControllerEditedImage]
196
+ editedImage = info[UIImagePickerControllerEditedImage]
195
197
  originalImage = info[UIImagePickerControllerOriginalImage]
196
198
  if editedImage
197
199
  imageToUse = editedImage
@@ -201,7 +203,7 @@ class XLFormImageSelectorCell < XLFormBaseCell
201
203
  setImageValue(imageToUse)
202
204
 
203
205
  if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
204
- if @popover_controller and @popover_controller.isPopoverVisible
206
+ if @popover_controller && @popover_controller.isPopoverVisible
205
207
  @popover_controller.dismissPopoverAnimated(true)
206
208
  end
207
209
  else
@@ -213,9 +215,9 @@ class XLFormImageSelectorCell < XLFormBaseCell
213
215
  def imageview
214
216
  return @imageview if @imageview
215
217
 
216
- @imageview = UIImageView.autolayoutView
218
+ @imageview = UIImageView.autolayoutView
217
219
  @imageview.layer.masksToBounds = true
218
- @imageview.contentMode = UIViewContentModeScaleAspectFit
220
+ @imageview.contentMode = UIViewContentModeScaleAspectFit
219
221
  @imageview
220
222
  end
221
223
 
@@ -224,4 +226,4 @@ class XLFormImageSelectorCell < XLFormBaseCell
224
226
  @text_label = UILabel.autolayoutView
225
227
  end
226
228
 
227
- end
229
+ end
@@ -8,7 +8,7 @@ module ProMotion
8
8
  end
9
9
 
10
10
  def valid?(row)
11
- return nil if row.nil? or row.value.nil? or !row.value.is_a?(String)
11
+ return nil if row.nil? || row.value.nil? || !row.value.is_a?(String)
12
12
 
13
13
  !@regex.match(row.value).nil?
14
14
  end