ProMotion-XLForm 0.0.9 → 0.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fc58053fd275bef181a86bb72f899c4b18f19cf
4
- data.tar.gz: 9999d16ffe8002ce607fdd01456dd94fd0394312
3
+ metadata.gz: ee27a2aaaa760891254d3dc74750627ba2e5f3dd
4
+ data.tar.gz: 7b94d7fa1b9a90a67683ef6f5857c67bc7140083
5
5
  SHA512:
6
- metadata.gz: 3eeeaac0957b4c65a68cd69a4f03b778f1416c978da4211375b0dcf7e709d149803b2855793ea0888bdf12e44f500a102847473a49f2654ede5866b107e23337
7
- data.tar.gz: 7962d3602e3ed6fff45265b710250a8d3783a8e20350e3e747b64cbf8a18a26863492a41fb7570bcb365d063afd969bae884a5f7c982beda312c87f8748ac14d
6
+ metadata.gz: 2aa17d7cdc982ab7c05070e25f707b3776117be81817d917670bb7bc1263003aa49af8cf98f7c028db215d115736b67a153043c9ae3547be4d81d3b46de16b85
7
+ data.tar.gz: aec5cdfd8915d050124fb65b0fabfe7d001cc4509b465fc1dd713114502133e4b6df5577389de4d5bc7b364b0688d10bb2592880e3a839607a2bffd94a6b49cc
data/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  ProMotion-XLForm provides a PM::XLFormScreen for [ProMotion](https://github.com/clearsightstudio/ProMotion) powered by the CocoaPod [XLForm](https://github.com/xmartlabs/XLForm).
4
4
 
5
- ## Warning
6
- This gem is currently in very early-stage. Use it at your own risk :)
7
-
8
5
  [![Build Status](https://travis-ci.org/bmichotte/ProMotion-XLForm.svg?branch=master)](https://travis-ci.org/bmichotte/ProMotion-XLForm) [![Gem Version](https://badge.fury.io/rb/ProMotion-XLForm.svg)](http://badge.fury.io/rb/ProMotion-XLForm)
9
6
 
10
7
  ## Installation
@@ -115,6 +112,7 @@ class TestFormScreen < PM::XLFormScreen
115
112
  on_cancel: :cancel_form # will be called when you touch cancel
116
113
 
117
114
  def save_form(values)
115
+ dismiss_keyboard
118
116
  mp values
119
117
  end
120
118
 
@@ -125,7 +123,8 @@ end
125
123
 
126
124
  ### Getting values
127
125
 
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?`.
126
+ You can get the values of your form with `values`. You can call `dismiss_keyboard` before before calling `values` to ensure you capture the input from the currently focused form element.
127
+ You can also get validation errors with `validation_errors` and check if the form is valid with `valid?`.
129
128
  You can also get a specific value with `value_for_cell(:my_cell)`.
130
129
 
131
130
  ### Events
@@ -6,9 +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")
10
- app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_image_selector_cell.rb")
11
- app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_color_selector_cell.rb")
9
+
12
10
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_class_methods.rb")
13
11
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_module.rb")
14
12
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_view_controller.rb")
@@ -19,11 +17,19 @@ Motion::Project::App.setup do |app|
19
17
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_helper.rb")
20
18
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_cell_builder.rb")
21
19
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_section_builder.rb")
20
+
21
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_cell.rb")
22
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_image_selector_cell.rb")
23
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_color_selector_cell.rb")
24
+
22
25
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/value_transformer.rb")
26
+
23
27
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/validator.rb")
24
28
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/url_validator.rb")
25
29
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/regex_validator.rb")
26
30
 
31
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/ui_alert_controller.rb")
32
+
27
33
  app.pods do
28
34
  pod 'XLForm', '~> 3.0.0'
29
35
  pod 'RSColorPicker'
@@ -1,5 +1,10 @@
1
1
  module ProMotion
2
2
  class XLFormCell < XLFormBaseCell
3
+ include ProMotion::TableViewCellModule
4
+
5
+ def check_deprecated_styles
6
+ # just ignore ProMotion messages
7
+ end
3
8
 
4
9
  def value=(value)
5
10
  rowDescriptor.value = value
@@ -1,27 +1,30 @@
1
- class XLFormColorSelectorCell < XLFormBaseCell
2
- def configure
3
- super.tap do
4
- self.selectionStyle = UITableViewCellSelectionStyleNone
1
+ module ProMotion
2
+ class XLFormColorSelectorCell < XLFormCell
3
+
4
+ def setup(data_cell, screen)
5
+ super
6
+
5
7
  @color_view = UIView.alloc.initWithFrame [[0, 0], [80, 30]]
6
8
  @color_view.contentMode = UIViewContentModeScaleAspectFit
7
9
  @color_view.layer.borderWidth = 1
8
10
  @color_view.layer.borderColor = UIColor.blackColor.CGColor
9
11
  @color_view.backgroundColor = UIColor.whiteColor
10
- tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: 'on_color_tap:')
11
- self.addGestureRecognizer(tap)
12
-
13
12
  self.accessoryView = @color_view
13
+
14
+ self.selectionStyle = UITableViewCellSelectionStyleNone
15
+ self.backgroundColor = UIColor.whiteColor
16
+ self.separatorInset = UIEdgeInsetsZero
14
17
  end
15
- end
16
18
 
17
- def on_color_tap(_)
18
- unless self.rowDescriptor.disabled
19
+ def formDescriptorCellDidSelectedWithFormController(controller)
20
+ return if self.rowDescriptor.disabled
21
+
19
22
  self.formViewController.view.endEditing(true)
20
23
 
21
24
  size = if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
22
25
  [400, 440]
23
26
  else
24
- [320, 440]
27
+ UIScreen.mainScreen.bounds.size
25
28
  end
26
29
  color_chooser = PMXLColorChooser.alloc.initWithFrame [[0, 0], size]
27
30
  color_chooser.delegate = self
@@ -61,30 +64,24 @@ class XLFormColorSelectorCell < XLFormBaseCell
61
64
  end
62
65
  end
63
66
  end
64
- end
65
67
 
66
- def hide_picker(_)
67
- self.formViewController.dismissViewControllerAnimated(true, completion: nil)
68
- end
68
+ def hide_picker(_)
69
+ self.formViewController.dismissViewControllerAnimated(true, completion: nil)
70
+ end
69
71
 
70
- def update
71
- super.tap do
72
- self.textLabel.text = (self.rowDescriptor.isRequired && self.rowDescriptor.title) ? "#{self.rowDescriptor.title}*" : self.rowDescriptor.title
73
- @color_view.frame = [[305.0, 7.0], [80.0, 30.0]]
74
- color = self.rowDescriptor.value
72
+ def update
73
+ color = value
75
74
  unless color
76
75
  color = UIColor.whiteColor
77
76
  end
78
- @color_view.layer.borderColor = UIColor.blackColor.CGColor
79
77
  @color_view.backgroundColor = color
80
- self.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
81
78
  end
82
- end
83
79
 
84
- def colorPickerDidChangeSelection(color_picker)
85
- color = color_picker.selectionColor
86
- @color_view.backgroundColor = color
87
- self.rowDescriptor.value = color
80
+ def colorPickerDidChangeSelection(color_picker)
81
+ color = color_picker.selectionColor
82
+ @color_view.backgroundColor = color
83
+ self.value = color
84
+ end
88
85
  end
89
86
  end
90
87
 
@@ -1,229 +1,153 @@
1
- class XLFormImageSelectorCell < XLFormBaseCell
1
+ module ProMotion
2
+ class XLFormImageSelectorCell < XLFormCell
2
3
 
3
- attr_accessor :imageview, :text_label
4
+ def setup(data_cell, screen)
5
+ super
4
6
 
5
- def configure
6
- super
7
- @image_height = 100.0
8
- @image_width = 100.0
9
- self.selectionStyle = UITableViewCellSelectionStyleNone
10
- self.backgroundColor = UIColor.whiteColor
11
- self.separatorInset = UIEdgeInsetsZero
7
+ size = (data_cell[:height] || 100) - 20
12
8
 
13
- self.contentView.addSubview(imageview)
14
- self.contentView.addSubview(text_label)
15
- text_label.addObserver(self, forKeyPath: "text", options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew, context: 0)
16
- end
17
-
18
- def update
19
- text_label.text = self.rowDescriptor.title
20
- imageview.image = self.rowDescriptor.value
21
-
22
- text_label.setFont(UIFont.preferredFontForTextStyle(UIFontTextStyleBody))
23
- text_label.sizeToFit
24
- updateConstraints
25
- end
9
+ @imageview = UIImageView.alloc.initWithFrame([[0, 0], [size, size]])
10
+ self.accessoryView = @imageview
26
11
 
27
- def self.formDescriptorCellHeightForRowDescriptor(_)
28
- 120.0
29
- end
12
+ self.selectionStyle = UITableViewCellSelectionStyleNone
13
+ self.backgroundColor = UIColor.whiteColor
14
+ self.separatorInset = UIEdgeInsetsZero
15
+ end
30
16
 
31
- def formDescriptorCellDidSelectedWithFormController(controller)
32
- if Kernel.const_defined?("UIAlertController") && UIAlertController.respond_to?(:'alertControllerWithTitle:message:preferredStyle:')
33
- alert = UIAlertController.alertControllerWithTitle(self.rowDescriptor.selectorTitle,
34
- message: nil,
35
- preferredStyle: UIAlertControllerStyleActionSheet)
17
+ def update
18
+ @imageview.image = value
19
+ end
36
20
 
37
- alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Choose From Library", nil),
38
- style: UIAlertActionStyleDefault,
39
- handler: lambda { |_|
40
- open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
41
- }))
21
+ def formDescriptorCellDidSelectedWithFormController(controller)
22
+ if Kernel.const_defined?("UIAlertController") && UIAlertController.respond_to?(:'alertControllerWithTitle:message:preferredStyle:')
23
+ alert = UIAlertController.alertControllerWithTitle(self.rowDescriptor.selectorTitle,
24
+ message: nil,
25
+ preferredStyle: UIAlertControllerStyleActionSheet)
42
26
 
43
- if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
44
- alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Take Photo", nil),
27
+ alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Choose From Library", nil),
45
28
  style: UIAlertActionStyleDefault,
46
29
  handler: lambda { |_|
47
- open_from_alert(UIImagePickerControllerSourceTypeCamera)
30
+ open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
48
31
  }))
49
- end
50
32
 
51
- if
52
- alert.modalPresentationStyle = UIModalPresentationPopover
53
- alert.popoverPresentationController.sourceView = self.contentView
54
- alert.popoverPresentationController.sourceRect = self.contentView.bounds
55
- end
33
+ if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
34
+ alert.addAction(UIAlertAction.actionWithTitle(NSLocalizedString("Take Photo", nil),
35
+ style: UIAlertActionStyleDefault,
36
+ handler: lambda { |_|
37
+ open_from_alert(UIImagePickerControllerSourceTypeCamera)
38
+ }))
39
+ end
40
+
41
+ if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
42
+ alert.modalPresentationStyle = UIModalPresentationPopover
43
+ alert.popoverPresentationController.sourceView = self.contentView
44
+ alert.popoverPresentationController.sourceRect = self.contentView.bounds
45
+ end
46
+
47
+ present = -> {
48
+ self.formViewController.presentViewController(alert, animated: true, completion: nil)
49
+ }
50
+ if self.formViewController.presentedViewController
51
+ self.formViewController.dismissViewControllerAnimated(true, completion: present)
52
+ else
53
+ present.call
54
+ end
56
55
 
57
- present = -> {
58
- self.formViewController.presentViewController(alert, animated: true, completion: nil)
59
- }
60
- if self.formViewController.presentedViewController
61
- self.formViewController.dismissViewControllerAnimated(true, completion: present)
62
56
  else
63
- present.call
57
+ if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
58
+ action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
59
+ delegate: self,
60
+ cancelButtonTitle: NSLocalizedString("Cancel", nil),
61
+ destructiveButtonTitle: nil,
62
+ otherButtonTitles: NSLocalizedString("Choose From Library", nil), NSLocalizedString("Take Photo", nil), nil)
63
+ else
64
+ action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
65
+ delegate: self,
66
+ cancelButtonTitle: NSLocalizedString("Cancel", nil),
67
+ destructiveButtonTitle: nil,
68
+ otherButtonTitles: NSLocalizedString("Choose From Library", nil), nil)
69
+ end
70
+ action_sheet.tag = self.tag
71
+ action_sheet.showInView(self.formViewController.view)
64
72
  end
65
-
66
- else
67
- if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
68
- action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
69
- delegate: self,
70
- cancelButtonTitle: NSLocalizedString("Cancel", nil),
71
- destructiveButtonTitle: nil,
72
- otherButtonTitles: NSLocalizedString("Choose From Library", nil), NSLocalizedString("Take Photo", nil), nil)
73
- else
74
- action_sheet = UIActionSheet.alloc.initWithTitle(self.rowDescriptor.selectorTitle,
75
- delegate: self,
76
- cancelButtonTitle: NSLocalizedString("Cancel", nil),
77
- destructiveButtonTitle: nil,
78
- otherButtonTitles: NSLocalizedString("Choose From Library", nil), nil)
79
- end
80
- action_sheet.tag = self.tag
81
- action_sheet.showInView(self.formViewController.view)
82
73
  end
83
- end
84
74
 
85
- def updateConstraints
86
- ui_components = { "image" => imageview, "text" => text_label }
87
-
88
- self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-16-[text]", options: 0, metrics: 0, views: ui_components))
89
- self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-6-[text]", options: 0, metrics: 0, views: ui_components))
90
-
91
- self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
92
- attribute: NSLayoutAttributeTop,
93
- relatedBy: NSLayoutRelationEqual,
94
- toItem: self.contentView,
95
- attribute: NSLayoutAttributeTop,
96
- multiplier: 1.0,
97
- constant: 10.0))
98
-
99
- self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
100
- attribute: NSLayoutAttributeBottom,
101
- relatedBy: NSLayoutRelationEqual,
102
- toItem: self.contentView,
103
- attribute: NSLayoutAttributeBottom,
104
- multiplier: 1.0,
105
- constant: -10.0))
106
-
107
- self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[image(width)]", options: 0, metrics: { "width" => @image_width }, views: ui_components))
108
- self.contentView.addConstraint(NSLayoutConstraint.constraintWithItem(imageview,
109
- attribute: NSLayoutAttributeCenterX,
110
- relatedBy: NSLayoutRelationEqual,
111
- toItem: self.contentView,
112
- attribute: NSLayoutAttributeCenterX,
113
- multiplier: 1.0,
114
- constant: 0.0))
115
- super
116
- end
75
+ # trick to force the status bar to be hidden when presenting the UIImagePickerViewController
76
+ def navigationController(_, willShowViewController: _, animated: _)
77
+ UIApplication.sharedApplication.setStatusBarHidden true
78
+ end
117
79
 
118
- # trick to force the status bar to be hidden when presenting the UIImagePickerViewController
119
- def navigationController(_, willShowViewController: _, animated: _)
120
- UIApplication.sharedApplication.setStatusBarHidden true
121
- end
80
+ # UIActionSheetDelegate
81
+ def actionSheet(action_sheet, clickedButtonAtIndex: button_index)
82
+ return if button_index == action_sheet.cancelButtonIndex
122
83
 
123
- def setImageValue(image)
124
- self.rowDescriptor.value = image
125
- imageview.image = image
126
- end
84
+ title = action_sheet.buttonTitleAtIndex(button_index)
127
85
 
128
- def observeValueForKeyPath(key_path, ofObject: object, change: change, context: _)
129
- if object == text_label && key_path == "text"
130
- if change[NSKeyValueChangeKindKey] == NSKeyValueChangeSetting
131
- text_label.sizeToFit
132
- frame = text_label.frame
133
- frame.origin = [16, 4]
134
- text_label.frame = frame
135
- self.contentView.needsUpdateConstraints
86
+ case title
87
+ when NSLocalizedString("Choose From Library", nil)
88
+ open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
89
+ when NSLocalizedString("Take Photo", nil)
90
+ open_from_alert(UIImagePickerControllerSourceTypeCamera)
91
+ else
92
+ return
136
93
  end
137
94
  end
138
- end
139
-
140
- def dealloc
141
- text_label.removeObserver(self, forKeyPath: "text")
142
- end
143
95
 
144
- # UIActionSheetDelegate
145
- def actionSheet(action_sheet, clickedButtonAtIndex: button_index)
146
- return if button_index == action_sheet.cancelButtonIndex
147
-
148
- title = action_sheet.buttonTitleAtIndex(button_index)
96
+ def open_from_alert(source)
97
+ open = -> {
98
+ open_picker(source)
99
+ }
149
100
 
150
- case title
151
- when NSLocalizedString("Choose From Library", nil)
152
- open_from_alert(UIImagePickerControllerSourceTypePhotoLibrary)
153
- when NSLocalizedString("Take Photo", nil)
154
- open_from_alert(UIImagePickerControllerSourceTypeCamera)
101
+ if @popover_controller && @popover_controller.isPopoverVisible
102
+ @popover_controller.dismissPopoverAnimated(true)
103
+ open.call
104
+ elsif self.formViewController.presentedViewController
105
+ self.formViewController.dismissViewControllerAnimated(true, completion: open)
155
106
  else
156
- return
157
- end
158
- end
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
-
175
- def open_picker(source)
176
- @image_picker = UIImagePickerController.alloc.init
177
- @image_picker.delegate = self
178
- @image_picker.allowsEditing = true
179
- @image_picker.sourceType = source
180
-
181
- if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
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)
187
- else
188
- self.formViewController.presentViewController(@image_picker,
189
- animated: true,
190
- completion: nil)
107
+ open.call
108
+ end
191
109
  end
192
- end
193
110
 
194
- # UIImagePickerControllerDelegate
195
- def imagePickerController(_, didFinishPickingMediaWithInfo: info)
196
- editedImage = info[UIImagePickerControllerEditedImage]
197
- originalImage = info[UIImagePickerControllerOriginalImage]
198
- if editedImage
199
- imageToUse = editedImage
200
- else
201
- imageToUse = originalImage
111
+ def open_picker(source)
112
+ @image_picker = UIImagePickerController.alloc.init
113
+ @image_picker.delegate = self
114
+ @image_picker.allowsEditing = true
115
+ @image_picker.sourceType = source
116
+
117
+ if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
118
+ @popover_controller = UIPopoverController.alloc.initWithContentViewController(@image_picker)
119
+ @popover_controller.presentPopoverFromRect(self.contentView.frame,
120
+ inView: self.formViewController.view,
121
+ permittedArrowDirections: UIPopoverArrowDirectionAny,
122
+ animated: true)
123
+ else
124
+ self.formViewController.presentViewController(@image_picker,
125
+ animated: true,
126
+ completion: nil)
127
+ end
202
128
  end
203
- setImageValue(imageToUse)
204
129
 
205
- if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
206
- if @popover_controller && @popover_controller.isPopoverVisible
207
- @popover_controller.dismissPopoverAnimated(true)
130
+ # UIImagePickerControllerDelegate
131
+ def imagePickerController(_, didFinishPickingMediaWithInfo: info)
132
+ editedImage = info[UIImagePickerControllerEditedImage]
133
+ originalImage = info[UIImagePickerControllerOriginalImage]
134
+ if editedImage
135
+ imageToUse = editedImage
136
+ else
137
+ imageToUse = originalImage
138
+ end
139
+
140
+ self.value = imageToUse
141
+ @imageview.image = imageToUse
142
+
143
+ if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
144
+ if @popover_controller && @popover_controller.isPopoverVisible
145
+ @popover_controller.dismissPopoverAnimated(true)
146
+ end
147
+ else
148
+ self.formViewController.dismissViewControllerAnimated(true, completion: nil)
208
149
  end
209
- else
210
- self.formViewController.dismissViewControllerAnimated(true, completion: nil)
211
150
  end
212
- end
213
-
214
- # Properties
215
- def imageview
216
- return @imageview if @imageview
217
151
 
218
- @imageview = UIImageView.autolayoutView
219
- @imageview.layer.masksToBounds = true
220
- @imageview.contentMode = UIViewContentModeScaleAspectFit
221
- @imageview
222
152
  end
223
-
224
- def text_label
225
- return @text_label if @text_label
226
- @text_label = UILabel.autolayoutView
227
- end
228
-
229
153
  end
@@ -0,0 +1,14 @@
1
+ class UIAlertController
2
+ # workaround for
3
+ # Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIAlertController:supportedInterfaceOrientations was invoked recursively!'
4
+
5
+ def supportedInterfaceOrientations
6
+ orientation = UIApplication.sharedApplication.statusBarOrientation
7
+
8
+ orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskLandscape
9
+ end
10
+
11
+ def shouldAutorotate
12
+ true
13
+ end
14
+ end
@@ -14,7 +14,6 @@ module ProMotion
14
14
  end
15
15
 
16
16
  cell = XLFormRowDescriptor.formRowDescriptorWithTag(tag, rowType: row_type(type), title: title)
17
- cell.cell_data = cell_data
18
17
 
19
18
  cell.required = cell_data[:required]
20
19
 
@@ -64,6 +63,7 @@ module ProMotion
64
63
  # image
65
64
  if cell_data[:type] == :image
66
65
  cell_class = XLFormImageSelectorCell if cell_class.nil?
66
+ cell_data[:height] ||= 100
67
67
  elsif cell_data[:type] == :color
68
68
  cell_class = XLFormColorSelectorCell if cell_class.nil?
69
69
  end
@@ -169,12 +169,15 @@ module ProMotion
169
169
  end
170
170
  end
171
171
 
172
- if value === true || value === false
172
+ if value.is_a?(TrueClass) && (value === true || value === false)
173
173
  value = value ? 1 : 0
174
174
  end
175
175
 
176
176
  cell.value = value
177
177
 
178
+ # move this at the end so we can "override" some cell_data
179
+ cell.cell_data = cell_data
180
+
178
181
  cell
179
182
  end
180
183
 
@@ -27,6 +27,10 @@ class XLFormRowDescriptor
27
27
  row_copy
28
28
  end
29
29
 
30
+ def enabled=(value)
31
+ self.disabled = !value
32
+ end
33
+
30
34
  def options=(options)
31
35
  self.selectorOptions = parse_options(options)
32
36
  end
@@ -42,6 +46,27 @@ class XLFormRowDescriptor
42
46
  XLFormOptionsObject.formOptionsObjectWithValue(val, displayText: text)
43
47
  end
44
48
  end
49
+
50
+ def cellForFormController(form_controller)
51
+ unless self.cell
52
+ cell_class = self.cellClass ? self.cellClass : XLFormViewController.cellClassesForRowDescriptorTypes[self.rowType]
53
+ if cell_class.is_a?(String)
54
+ bundle = NSBundle.bundleForClass(cell_class.to_s)
55
+ if bundle.pathForResource(cell_class, ofType: "nib")
56
+ self.cell = bundle.loadNibNamed(cell_class, owner: nil, options: nil).first
57
+ end
58
+ else
59
+ self.cell = cell_class.alloc.initWithStyle(self.cellStyle, reuseIdentifier: nil)
60
+ end
61
+
62
+ if self.cell && self.cell.respond_to?(:setup)
63
+ self.cell.setup(cell_data, form_controller)
64
+ end
65
+ self.configureCellAtCreationTime
66
+ end
67
+
68
+ self.cell
69
+ end
45
70
  end
46
71
 
47
72
  class XLFormSectionDescriptor
@@ -127,6 +127,10 @@ module ProMotion
127
127
  self.form.formRowWithTag(tag)
128
128
  end
129
129
 
130
+ def cell_at_path(path)
131
+ self.form.formRowAtIndex(path)
132
+ end
133
+
130
134
  def reload(cell)
131
135
  reloadFormRow(cell)
132
136
  end
@@ -184,6 +188,11 @@ module ProMotion
184
188
  def enabled?
185
189
  !self.form.isDisabled
186
190
  end
191
+
192
+ # dismiss keyboard
193
+ def dismiss_keyboard
194
+ self.view.endEditing true
195
+ end
187
196
 
188
197
  protected
189
198
  def on_cancel(_)
@@ -267,6 +276,19 @@ module ProMotion
267
276
  @form_builder.create_cell(cell_data)
268
277
  end
269
278
 
279
+ # override XLFormViewController
280
+ def tableView(table_view, heightForRowAtIndexPath: index_path)
281
+ row = cell_at_path(index_path)
282
+ cell = row.cellForFormController(self)
283
+ cell_class = cell.class
284
+ if cell_class.respond_to?(:formDescriptorCellHeightForRowDescriptor)
285
+ return cell_class.formDescriptorCellHeightForRowDescriptor(row)
286
+ elsif row.respond_to?(:cell_data) && row.cell_data[:height]
287
+ return row.cell_data[:height]
288
+ end
289
+ self.tableView.rowHeight
290
+ end
291
+
270
292
  private
271
293
  def trigger_action(action, section_or_row, index_path)
272
294
  case arity = action.arity
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion-XLForm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Michotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-12 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion
@@ -92,6 +92,7 @@ files:
92
92
  - lib/ProMotion/XLForm/cells/xl_form_cell.rb
93
93
  - lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb
94
94
  - lib/ProMotion/XLForm/cells/xl_form_image_selector_cell.rb
95
+ - lib/ProMotion/XLForm/ui_alert_controller.rb
95
96
  - lib/ProMotion/XLForm/validators/regex_validator.rb
96
97
  - lib/ProMotion/XLForm/validators/url_validator.rb
97
98
  - lib/ProMotion/XLForm/validators/validator.rb