ProMotion-XLForm 0.0.10 → 0.0.11

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: ee27a2aaaa760891254d3dc74750627ba2e5f3dd
4
- data.tar.gz: 7b94d7fa1b9a90a67683ef6f5857c67bc7140083
3
+ metadata.gz: d4953d1198db5beb180fb0a772c4ed0f4974ffff
4
+ data.tar.gz: 15c71318fed226e75954bf103ab07671142fbc17
5
5
  SHA512:
6
- metadata.gz: 2aa17d7cdc982ab7c05070e25f707b3776117be81817d917670bb7bc1263003aa49af8cf98f7c028db215d115736b67a153043c9ae3547be4d81d3b46de16b85
7
- data.tar.gz: aec5cdfd8915d050124fb65b0fabfe7d001cc4509b465fc1dd713114502133e4b6df5577389de4d5bc7b364b0688d10bb2592880e3a839607a2bffd94a6b49cc
6
+ metadata.gz: b19ad4e1ba5c0017ac3955ebae76adf3f733c87289b2a1b59a4aaf948886e95635cb6e0092510d1962f6cd71811f1e27cc61e54b5a2460ad61a5c7287a158486
7
+ data.tar.gz: 8fe4483864350bf7a1866bb099710475d763e6ee10e41de5e82d72e75555fbc132a220a1feaabd67e3e4fafe48ec5293855c009b8202e804399783b9412a8537
data/README.md CHANGED
@@ -26,36 +26,40 @@ To create a form, create a new `PM::XLFormScreen` and implement `form_data`.
26
26
  ```ruby
27
27
  class TestFormScreen < PM::XLFormScreen
28
28
  def form_data
29
- [
30
- {
31
- title: 'Account information',
32
- cells: [
33
- {
34
- title: 'Email',
35
- name: :email,
36
- type: :email,
37
- placeholder: 'Enter your email',
38
- required: true
39
- },
40
- {
41
- title: 'Name',
42
- name: :name,
43
- type: :text,
44
- value: 'Default value'
45
- },
46
- {
47
- title: 'Sex',
48
- name: :sex,
49
- type: :selector_push,
50
- options: {
51
- male: 'Male',
52
- female: 'Female',
53
- other: 'Other'
29
+ genders = [
30
+ { id: :male, name: 'Male' },
31
+ { id: :female, name: 'Female' },
32
+ { id: :other, name: 'Other' },
33
+ ]
34
+
35
+ [
36
+ {
37
+ title: 'Account information',
38
+ cells: [
39
+ {
40
+ title: 'Email',
41
+ name: :email,
42
+ type: :email,
43
+ placeholder: 'Enter your email',
44
+ required: true
45
+ },
46
+ {
47
+ title: 'Name',
48
+ name: :name,
49
+ type: :text,
50
+ value: 'Default value'
51
+ },
52
+ {
53
+ title: 'Gender',
54
+ name: :gender,
55
+ type: :selector_push,
56
+ options: Hash[genders.map do |gender|
57
+ [gender[:id], gender[:name]]
58
+ end]
54
59
  }
55
- }
56
- ]
57
- }
58
- ]
60
+ ]
61
+ }
62
+ ]
59
63
  end
60
64
  end
61
65
  ```
@@ -121,6 +125,31 @@ class TestFormScreen < PM::XLFormScreen
121
125
  end
122
126
  ```
123
127
 
128
+ If you don't want the default navigation controller buttons, you could add something like
129
+
130
+ ```ruby
131
+
132
+ form_options on_save: :my_save_method
133
+
134
+ def form_data
135
+ [
136
+ {
137
+ title: 'Save',
138
+ name: :save,
139
+ type: :button,
140
+ on_click: -> (cell) {
141
+ on_save(nil)
142
+ }
143
+ }
144
+ ]
145
+ end
146
+
147
+ def my_save_method(values)
148
+ mp values
149
+ end
150
+
151
+ ```
152
+
124
153
  ### Getting values
125
154
 
126
155
  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.
@@ -17,21 +17,17 @@ Motion::Project::App.setup do |app|
17
17
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_helper.rb")
18
18
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_cell_builder.rb")
19
19
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_section_builder.rb")
20
-
21
20
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_cell.rb")
22
21
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_image_selector_cell.rb")
23
22
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/cells/xl_form_color_selector_cell.rb")
24
-
25
23
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/value_transformer.rb")
26
-
27
24
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/validator.rb")
28
25
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/url_validator.rb")
29
26
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/regex_validator.rb")
30
-
31
27
  app.files << File.join(lib_dir_path, "ProMotion/XLForm/ui_alert_controller.rb")
32
28
 
33
29
  app.pods do
34
- pod 'XLForm', '~> 3.0.0'
30
+ pod 'XLForm', :head
35
31
  pod 'RSColorPicker'
36
32
  end
37
33
  end
@@ -1,10 +1,14 @@
1
1
  module ProMotion
2
2
  class XLFormImageSelectorCell < XLFormCell
3
3
 
4
+ def self.formDescriptorCellHeightForRowDescriptor(_)
5
+ 100
6
+ end
7
+
4
8
  def setup(data_cell, screen)
5
9
  super
6
10
 
7
- size = (data_cell[:height] || 100) - 20
11
+ size = (data_cell[:height] || 100) - 20
8
12
 
9
13
  @imageview = UIImageView.alloc.initWithFrame([[0, 0], [size, size]])
10
14
  self.accessoryView = @imageview
@@ -12,6 +16,7 @@ module ProMotion
12
16
  self.selectionStyle = UITableViewCellSelectionStyleNone
13
17
  self.backgroundColor = UIColor.whiteColor
14
18
  self.separatorInset = UIEdgeInsetsZero
19
+ self.editingAccessoryView = self.accessoryView
15
20
  end
16
21
 
17
22
  def update
@@ -45,7 +50,9 @@ module ProMotion
45
50
  end
46
51
 
47
52
  present = -> {
48
- self.formViewController.presentViewController(alert, animated: true, completion: nil)
53
+ Dispatch::Queue.main.async do
54
+ self.formViewController.presentViewController(alert, animated: true, completion: nil)
55
+ end
49
56
  }
50
57
  if self.formViewController.presentedViewController
51
58
  self.formViewController.dismissViewControllerAnimated(true, completion: present)
@@ -116,10 +123,12 @@ module ProMotion
116
123
 
117
124
  if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
118
125
  @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)
126
+ Dispatch::Queue.main.async do
127
+ @popover_controller.presentPopoverFromRect(self.contentView.frame,
128
+ inView: self.formViewController.view,
129
+ permittedArrowDirections: UIPopoverArrowDirectionAny,
130
+ animated: true)
131
+ end
123
132
  else
124
133
  self.formViewController.presentViewController(@image_picker,
125
134
  animated: true,
@@ -136,7 +145,7 @@ module ProMotion
136
145
  else
137
146
  imageToUse = originalImage
138
147
  end
139
-
148
+
140
149
  self.value = imageToUse
141
150
  @imageview.image = imageToUse
142
151
 
@@ -68,6 +68,12 @@ module ProMotion
68
68
  cell_class = XLFormColorSelectorCell if cell_class.nil?
69
69
  end
70
70
 
71
+ # image accessory
72
+ if cell_data[:image] && !cell_data[:image].is_a?(Hash)
73
+ accessory_image = cell_data[:image].is_a?(UIImage) ? cell_data[:image] : UIImage.imageNamed(cell_data[:image])
74
+ cell.cellConfigAtConfigure.setObject(accessory_image, forKey: "image")
75
+ end
76
+
71
77
  cell.cellClass = cell_class if cell_class
72
78
 
73
79
  # subcells
@@ -37,6 +37,8 @@ module ProMotion
37
37
  elsif tag.start_with?(':')
38
38
  tag[0] = ''
39
39
  end
40
+ tag += ".value.valueData" if predicate.is_a?(Hash) && predicate[:options]
41
+
40
42
  value = case value
41
43
  when nil
42
44
  'nil'
@@ -60,17 +60,17 @@ class XLFormRowDescriptor
60
60
  end
61
61
 
62
62
  if self.cell && self.cell.respond_to?(:setup)
63
- self.cell.setup(cell_data, form_controller)
63
+ self.cell.setup(cell_data, form_controller)
64
64
  end
65
65
  self.configureCellAtCreationTime
66
66
  end
67
-
68
- self.cell
67
+
68
+ self.cell
69
69
  end
70
70
  end
71
71
 
72
72
  class XLFormSectionDescriptor
73
- attr_accessor :section_data, :options
73
+ attr_accessor :section_data
74
74
 
75
75
  def self.section(section_data)
76
76
  title = section_data[:title]
@@ -81,21 +81,26 @@ class XLFormSectionDescriptor
81
81
 
82
82
  section = XLFormSectionDescriptor.formSectionWithTitle(title, sectionOptions: options, sectionInsertMode: insert_mode)
83
83
  section.section_data = section_data
84
- section.options = options
84
+
85
85
  section
86
86
  end
87
87
 
88
88
  def options=(value)
89
- @options = self.class.parse_section_options(value)
89
+ @section_options = self.class.parse_section_options(value)
90
90
  end
91
91
 
92
- def options
93
- @options
94
- end
92
+ # Since `sectionOptions` is a property on the Objective-C class and not a
93
+ # Ruby method we can't use `super` to fallback when overriding the method.
94
+ # To achieve the same thing we create an alias and use that instead.
95
+ alias :originalSectionOptions :sectionOptions
95
96
 
97
+ # This property/method is used in the Objective-C initializer and is called
98
+ # before we ever have a chance to set @section_options so we need to be able
99
+ # to fallback to the original.
96
100
  def sectionOptions
97
- options
101
+ @section_options || originalSectionOptions
98
102
  end
103
+ alias_method :options, :sectionOptions
99
104
 
100
105
  def self.parse_section_options(options)
101
106
  return section_options(:none) if options.nil?
@@ -188,7 +188,7 @@ module ProMotion
188
188
  def enabled?
189
189
  !self.form.isDisabled
190
190
  end
191
-
191
+
192
192
  # dismiss keyboard
193
193
  def dismiss_keyboard
194
194
  self.view.endEditing true
@@ -283,7 +283,7 @@ module ProMotion
283
283
  cell_class = cell.class
284
284
  if cell_class.respond_to?(:formDescriptorCellHeightForRowDescriptor)
285
285
  return cell_class.formDescriptorCellHeightForRowDescriptor(row)
286
- elsif row.respond_to?(:cell_data) && row.cell_data[:height]
286
+ elsif row.respond_to?(:cell_data) && row.cell_data && row.cell_data[:height]
287
287
  return row.cell_data[:height]
288
288
  end
289
289
  self.tableView.rowHeight
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.10
4
+ version: 0.0.11
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-25 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion