ProMotion-XLForm 0.0.5 → 0.0.6

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: 02a3b9031223eeed2b269133801248640428cda1
4
- data.tar.gz: c1122c6fb0bfc8b6b2ea35724f427fb9be5eb3d5
3
+ metadata.gz: 923b8c482cdd6c8250ad1d93674e85882d9b4b60
4
+ data.tar.gz: 2b0b483c71ab93876609e8cf21ceaa6841232520
5
5
  SHA512:
6
- metadata.gz: 6a89a59030b0d934598ed8570e1e1ce98da593527fa8ab24c608100f99acf53c34018ee26af9ba0e652a55fc7d4dd59c8dd858c712d35b95eb6222e5b0da0faf
7
- data.tar.gz: c2ad9973c172fc545d8a74d95b2a2a4d190dc497540812ae90946812c8c842d6025221b66a85060c662f17f713a0c4fd44a2f1793fca66a52b5f7db4446cd886
6
+ metadata.gz: 49b4311b2154e4cecb32d31df7410c864f07fc06a8957ff55fdfa894506bd82519f989d9b3e8d5ea1c53097d79da7e33c833799edb1f88e32f8f171a6bc93439
7
+ data.tar.gz: 68a272448f22f972bd4c4a56082d27317747052c2b75417b9d81bc779d831bff914149893754b8195d4fb7a4c9506055f5ee6d6850568125463c9e4c68948683
data/README.md CHANGED
@@ -102,7 +102,8 @@ end
102
102
  * :button
103
103
  * :info
104
104
  * :step_counter
105
- * :image
105
+ * :image (ProMotion-XLForm specific)
106
+ * :color (ProMotion-XLForm specific using [RSColorPicker](https://github.com/RSully/RSColorPicker))
106
107
 
107
108
  ### Class options
108
109
 
@@ -265,7 +266,7 @@ Finally, you can provide a PM::Validator with a `valid?(cell)` method.
265
266
  title: 'Appear when switch is on',
266
267
  name: :show_me,
267
268
  type: :info,
268
- visible: {
269
+ hidden: {
269
270
  # the cell name wich will "trigger" the visibility
270
271
  name: :hide_and_seek,
271
272
 
@@ -281,7 +282,7 @@ Finally, you can provide a PM::Validator with a `valid?(cell)` method.
281
282
  type: :info,
282
283
 
283
284
  # you can also write it this way
284
- visible: ':hide_and_seek == false'
285
+ hidden: ':hide_and_seek == false'
285
286
  # also valid ':some_text contains "a text"'
286
287
  # ':some_text not contains "a text"'
287
288
  }
@@ -291,7 +292,6 @@ Finally, you can provide a PM::Validator with a `valid?(cell)` method.
291
292
 
292
293
 
293
294
  ## Todo
294
- - Validations
295
295
  - Tests
296
296
  - A lot of other things :)
297
297
 
@@ -7,6 +7,7 @@ require 'motion-cocoapods'
7
7
  Motion::Project::App.setup do |app|
8
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
9
9
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_image_selector_cell.rb")
10
+ app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_color_selector_cell.rb")
10
11
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_class_methods.rb")
11
12
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_module.rb")
12
13
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_view_controller.rb")
@@ -21,5 +22,6 @@ Motion::Project::App.setup do |app|
21
22
 
22
23
  app.pods do
23
24
  pod 'XLForm', '~> 3.0.0'
25
+ pod 'RSColorPicker'
24
26
  end
25
27
  end
@@ -0,0 +1,175 @@
1
+ class XLFormColorSelectorCell < XLFormBaseCell
2
+ def configure
3
+ super.tap do
4
+ self.selectionStyle = UITableViewCellSelectionStyleNone
5
+ @color_view = UIView.alloc.initWithFrame [[0, 0], [80, 30]]
6
+ @color_view.contentMode = UIViewContentModeScaleAspectFit
7
+ @color_view.layer.borderWidth = 1
8
+ @color_view.layer.borderColor = UIColor.blackColor.CGColor
9
+ @color_view.backgroundColor = UIColor.whiteColor
10
+ tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: 'on_color_tap:')
11
+ self.addGestureRecognizer(tap)
12
+
13
+ self.accessoryView = @color_view
14
+ end
15
+ end
16
+
17
+ def on_color_tap(_)
18
+ unless self.rowDescriptor.disabled
19
+ self.formViewController.view.endEditing(true)
20
+
21
+ size = if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
22
+ [400, 440]
23
+ else
24
+ [320, 440]
25
+ end
26
+ color_chooser = PMXLColorChooser.alloc.initWithFrame [[0, 0], size]
27
+ color_chooser.delegate = self
28
+ color_chooser.color = self.rowDescriptor.value || UIColor.whiteColor
29
+
30
+ if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
31
+ controller = UIViewController.new
32
+ controller.view = color_chooser
33
+ @popover = UIPopoverController.alloc.initWithContentViewController controller
34
+ @popover.popoverContentSize = color_chooser.frame.size
35
+ f = self.contentView.convertRect(@color_view.frame, toView: self.formViewController.view)
36
+ @popover.presentPopoverFromRect(f,
37
+ inView: self.formViewController.view,
38
+ permittedArrowDirections: UIPopoverArrowDirectionAny,
39
+ animated: true)
40
+ else
41
+ controller = UIViewController.new
42
+ controller.view = color_chooser
43
+
44
+ navigation_controller = UINavigationController.alloc.initWithRootViewController(controller)
45
+ navigation_controller.navigationBar.translucent = false
46
+ right = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemDone,
47
+ target: self,
48
+ action: 'hide_picker:')
49
+ controller.navigationItem.rightBarButtonItem = right
50
+ if self.formViewController.presentedViewController
51
+ self.formViewController.dismissViewControllerAnimated(true,
52
+ completion: -> {
53
+ self.formViewController.presentViewController(navigation_controller,
54
+ animated: true,
55
+ completion: nil)
56
+ })
57
+ else
58
+ self.formViewController.presentViewController(navigation_controller,
59
+ animated: true,
60
+ completion: nil)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def hide_picker(_)
67
+ self.formViewController.dismissViewControllerAnimated(true, completion: nil)
68
+ end
69
+
70
+ def update
71
+ super.tap do
72
+ self.textLabel.text = (self.rowDescriptor.isRequired and 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
75
+ unless color
76
+ color = UIColor.whiteColor
77
+ end
78
+ @color_view.layer.borderColor = UIColor.blackColor.CGColor
79
+ @color_view.backgroundColor = color
80
+ self.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
81
+ end
82
+ end
83
+
84
+ def colorPickerDidChangeSelection(color_picker)
85
+ color = color_picker.selectionColor
86
+ @color_view.backgroundColor = color
87
+ self.rowDescriptor.value = color
88
+ end
89
+ end
90
+
91
+ class PMXLColorChooser < UIView
92
+
93
+ attr_accessor :delegate
94
+
95
+ def initWithFrame(frame)
96
+ super.tap do
97
+ self.backgroundColor = UIColor.whiteColor
98
+
99
+ picker_frame = CGRectInset(frame, 10, 10)
100
+ picker_frame.size.height = picker_frame.size.width
101
+ @color_picker = RSColorPickerView.alloc.initWithFrame picker_frame
102
+ self.addSubview(@color_picker)
103
+
104
+ slider_frame = [[10, CGRectGetMaxX(picker_frame) + 5], [CGRectGetWidth(picker_frame), 30]]
105
+ @slider = PMXLBrightnessSlider.alloc.initWithFrame slider_frame
106
+ @slider.color_picker = @color_picker
107
+ self.addSubview(@slider)
108
+ end
109
+ end
110
+
111
+ def color=(value)
112
+ @color_picker.setSelectionColor(value)
113
+ @slider.value = @color_picker.brightness
114
+ end
115
+
116
+ def color
117
+ @color_picker.selectionColor
118
+ end
119
+
120
+ def delegate=(value)
121
+ @delegate = value
122
+ @color_picker.delegate = value
123
+ end
124
+
125
+ end
126
+
127
+ class PMXLBrightnessSlider < UISlider
128
+ attr_accessor :color_picker
129
+
130
+ def initWithFrame(frame)
131
+ super.tap do
132
+ init_routine
133
+ end
134
+ end
135
+
136
+ def initWithCoder(decoder)
137
+ super.tap do
138
+ init_routine
139
+ end
140
+ end
141
+
142
+ def init_routine
143
+ self.minimumValue = 0.0
144
+ self.maximumValue = 1.0
145
+ self.continuous = true
146
+
147
+ self.enabled = true
148
+ self.userInteractionEnabled = true
149
+
150
+ self.addTarget(self,
151
+ action: 'slider_value_changed:',
152
+ forControlEvents: UIControlEventValueChanged)
153
+ end
154
+
155
+ def slider_value_changed(_)
156
+ color_picker.setBrightness(self.value)
157
+ end
158
+
159
+ def drawRect(rect)
160
+ ctx = UIGraphicsGetCurrentContext()
161
+
162
+ space = CGColorSpaceCreateDeviceGray()
163
+ colors = [UIColor.blackColor, UIColor.whiteColor]
164
+
165
+ gradient = CGGradientCreateWithColors(space, colors, nil)
166
+
167
+ CGContextDrawLinearGradient(ctx, gradient, CGPointZero, [rect.size.width, 0], 0)
168
+ end
169
+
170
+ def color_picker=(value)
171
+ @color_picker = value
172
+ self.value = @color_picker.brightness unless @color_picker.nil?
173
+ end
174
+
175
+ end
@@ -91,6 +91,8 @@ module ProMotion
91
91
  # image
92
92
  if cell_data[:type] == :image
93
93
  cell_class = XLFormImageSelectorCell if cell_class.nil?
94
+ elsif cell_data[:type] == :color
95
+ cell_class = XLFormColorSelectorCell if cell_class.nil?
94
96
  end
95
97
 
96
98
  cell.cellClass = cell_class if cell_class
@@ -114,23 +116,11 @@ module ProMotion
114
116
  cell.selectorTitle = cell_data[:selector_title] if cell_data[:selector_title]
115
117
  cell.options = cell_data[:options]
116
118
 
117
- value = cell_data[:value]
118
- if value and cell.selectorOptions
119
- cell.selectorOptions.each do |opt|
120
- if opt.formValue == value
121
- value = opt
122
- break
123
- end
124
- end
125
- end
126
-
127
- cell.value = value if value
128
-
129
119
  cell.disabled = !cell_data[:enabled] if cell_data[:enabled]
130
120
 
131
121
  # row visible
132
- if cell_data[:visible]
133
- predicate = cell_data[:visible]
122
+ if cell_data[:hidden]
123
+ predicate = cell_data[:hidden]
134
124
  if predicate.is_a?(Hash)
135
125
  tag = predicate[:name]
136
126
  operand = case predicate[:is]
@@ -222,6 +212,22 @@ module ProMotion
222
212
  end
223
213
  end
224
214
 
215
+ value = cell_data[:value]
216
+ if value and cell.selectorOptions
217
+ cell.selectorOptions.each do |opt|
218
+ if opt.formValue == value
219
+ value = opt
220
+ break
221
+ end
222
+ end
223
+ end
224
+
225
+ if value === true or value === false
226
+ value = value ? 1 : 0
227
+ end
228
+
229
+ cell.value = value
230
+
225
231
  section.addFormRow(cell)
226
232
 
227
233
  # multi sections
@@ -316,7 +322,8 @@ module ProMotion
316
322
  button: XLFormRowDescriptorTypeButton,
317
323
  info: XLFormRowDescriptorTypeInfo,
318
324
  step_counter: XLFormRowDescriptorTypeStepCounter,
319
- image: 'XLFormRowDescriptorTypeImage'
325
+ image: 'XLFormRowDescriptorTypeImage',
326
+ color: 'XLFormRowDescriptorTypeColor',
320
327
  }[symbol] || symbol
321
328
  end
322
329
 
@@ -17,15 +17,6 @@ end
17
17
 
18
18
  class XLFormRowDescriptor
19
19
 
20
- alias :old_copyWithZone :copyWithZone
21
-
22
- def copyWithZone(zone)
23
- row_descriptor_copy = old_copyWithZone(zone)
24
-
25
- row_descriptor_copy.valueTransformer = self.valueTransformer
26
- row_descriptor_copy
27
- end
28
-
29
20
  def options=(options)
30
21
  self.selectorOptions = parse_options(options)
31
22
  end
@@ -42,6 +42,8 @@ module ProMotion
42
42
  action: 'on_save:'
43
43
  }
44
44
  end
45
+
46
+ self.form_added if self.respond_to?(:form_added)
45
47
  end
46
48
 
47
49
  def form_data
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.5
4
+ version: 0.0.6
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-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - README.md
77
77
  - lib/ProMotion-XLForm.rb
78
+ - lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb
78
79
  - lib/ProMotion/XLForm/cells/xl_form_image_selector_cell.rb
79
80
  - lib/ProMotion/XLForm/validators/regex_validator.rb
80
81
  - lib/ProMotion/XLForm/validators/url_validator.rb