ProMotion-XLForm 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +46 -1
- data/lib/ProMotion-XLForm.rb +4 -0
- data/lib/ProMotion/XLForm/cells/xl_form_cell.rb +12 -0
- data/lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb +17 -17
- data/lib/ProMotion/XLForm/cells/xl_form_image_selector_cell.rb +80 -78
- data/lib/ProMotion/XLForm/validators/regex_validator.rb +1 -1
- data/lib/ProMotion/XLForm/xl_form.rb +54 -311
- data/lib/ProMotion/XLForm/xl_form_cell_builder.rb +182 -0
- data/lib/ProMotion/XLForm/xl_form_helper.rb +65 -0
- data/lib/ProMotion/XLForm/xl_form_patch.rb +78 -10
- data/lib/ProMotion/XLForm/xl_form_screen.rb +88 -40
- data/lib/ProMotion/XLForm/xl_form_section_builder.rb +48 -0
- data/lib/ProMotion/XLForm/xl_form_view_controller.rb +1 -1
- data/lib/ProMotion/XLForm/xl_sub_form_screen.rb +21 -21
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee73f17572e76ecaba9208e0073c277f1cba8264
|
4
|
+
data.tar.gz: 168afe00cae3b0a2c3bba1edb902d084e5784870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/ProMotion-XLForm.rb
CHANGED
@@ -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")
|
@@ -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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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:
|
37
|
+
inView: self.formViewController.view,
|
38
38
|
permittedArrowDirections: UIPopoverArrowDirectionAny,
|
39
|
-
animated:
|
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
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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:
|
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
|
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
|
-
|
152
|
-
|
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
|
8
|
-
@image_width
|
9
|
-
self.selectionStyle
|
7
|
+
@image_height = 100.0
|
8
|
+
@image_width = 100.0
|
9
|
+
self.selectionStyle = UITableViewCellSelectionStyleNone
|
10
10
|
self.backgroundColor = UIColor.whiteColor
|
11
|
-
self.separatorInset
|
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
|
32
|
+
if Kernel.const_defined?("UIAlertController")
|
33
33
|
alert = UIAlertController.alertControllerWithTitle(self.rowDescriptor.selectorTitle,
|
34
|
-
message:
|
34
|
+
message: nil,
|
35
35
|
preferredStyle: UIAlertControllerStyleActionSheet)
|
36
36
|
|
37
37
|
alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Choose From Library", nil),
|
38
|
-
style:
|
38
|
+
style: UIAlertActionStyleDefault,
|
39
39
|
handler: lambda { |_|
|
40
|
-
|
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:
|
45
|
+
style: UIAlertActionStyleDefault,
|
49
46
|
handler: lambda { |_|
|
50
|
-
|
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
|
-
|
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:
|
69
|
-
cancelButtonTitle:
|
69
|
+
delegate: self,
|
70
|
+
cancelButtonTitle: NSLocalizedString("Cancel", nil),
|
70
71
|
destructiveButtonTitle: nil,
|
71
|
-
otherButtonTitles:
|
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:
|
75
|
-
cancelButtonTitle:
|
75
|
+
delegate: self,
|
76
|
+
cancelButtonTitle: NSLocalizedString("Cancel", nil),
|
76
77
|
destructiveButtonTitle: nil,
|
77
|
-
otherButtonTitles:
|
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:
|
92
|
-
relatedBy:
|
93
|
-
toItem:
|
94
|
-
attribute:
|
92
|
+
attribute: NSLayoutAttributeTop,
|
93
|
+
relatedBy: NSLayoutRelationEqual,
|
94
|
+
toItem: self.contentView,
|
95
|
+
attribute: NSLayoutAttributeTop,
|
95
96
|
multiplier: 1.0,
|
96
|
-
constant:
|
97
|
+
constant: 10.0))
|
97
98
|
|
98
99
|
self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
|
99
|
-
attribute:
|
100
|
-
relatedBy:
|
101
|
-
toItem:
|
102
|
-
attribute:
|
100
|
+
attribute: NSLayoutAttributeBottom,
|
101
|
+
relatedBy: NSLayoutRelationEqual,
|
102
|
+
toItem: self.contentView,
|
103
|
+
attribute: NSLayoutAttributeBottom,
|
103
104
|
multiplier: 1.0,
|
104
|
-
constant:
|
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:
|
109
|
-
relatedBy:
|
110
|
-
toItem:
|
111
|
-
attribute:
|
109
|
+
attribute: NSLayoutAttributeCenterX,
|
110
|
+
relatedBy: NSLayoutRelationEqual,
|
111
|
+
toItem: self.contentView,
|
112
|
+
attribute: NSLayoutAttributeCenterX,
|
112
113
|
multiplier: 1.0,
|
113
|
-
constant:
|
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
|
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
|
132
|
-
frame.origin
|
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
|
-
|
152
|
+
open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
|
152
153
|
when NSLocalizedString("Take Photo", nil)
|
153
|
-
|
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
|
161
|
-
image_picker.delegate
|
162
|
-
image_picker.allowsEditing = true
|
163
|
-
image_picker.sourceType
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
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
|
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
|
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
|
218
|
+
@imageview = UIImageView.autolayoutView
|
217
219
|
@imageview.layer.masksToBounds = true
|
218
|
-
@imageview.contentMode
|
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
|