motion-form 0.4.0 → 0.5.0

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: a6bd42abc43d04185da76e9b3b8155e66e3bcbf2
4
- data.tar.gz: 3d356e286fb649efe437a0a54c7105a9cef21b82
3
+ metadata.gz: 17fd1f9a5463bdee3649012327557fd1d68eec18
4
+ data.tar.gz: dd0f05563e9c4d5a51594af6a869474bf1b4086c
5
5
  SHA512:
6
- metadata.gz: ae7c9d463b1ff1de5b945744c4f4b8301b7b5719046650502eba5dc035510ace9f441b79a5dbccf293eaa9550c69821e0ee5b3bd000025dccae074c8b46eb51e
7
- data.tar.gz: d37c7cca9a011af1f9daa58463dc620dd8e25736d15496186b9b2965e8a1017bd05167b70368dcf4f6f4500de09b3c424801aecd4a3b8db9de70035fe43d1a68
6
+ metadata.gz: e5945341d2e0ca7d5cd972a69497c08a410da80d197bbc001404887b36cfd4f407efb05e6106e513e68f4d1675bc7fd43f1160ce3f907b3757e4ee532740d5dd
7
+ data.tar.gz: 3202f56a063f6b2a8ae965ec8d2e09f1353426e784844908bd5f17c83c622a8799b665eac7ffe403e64a8bed380ca0fb9153e73372b7145df7e9d5cb5b53da12
data/README.md CHANGED
@@ -22,19 +22,19 @@ form = MotionForm.form_for(view) do |form|
22
22
  # Ex: form.section do |section|
23
23
 
24
24
  form.section 'Profile' do |section|
25
- section.input :name, icon: :contact, value: 'David Copperfield'
26
- section.input :username, icon: :user
27
- section.input :pinterest, icon: :pinterest
28
- section.input :twitter, icon: :twitter
29
- section.input :website, icon: :website
25
+ section.input :name, label: 'Your name', value: 'David Copperfield'
26
+ section.input :username, label: 'A username'
27
+ section.input :pinterest, label: 'Pinterest username'
28
+ section.input :twitter, label: 'Twitter username'
29
+ section.input :website, label: 'Personal website'
30
30
  section.text :bio, placeholder: 'Write a short bio...'
31
31
 
32
32
  section.button :submit, action: submit
33
33
  end
34
34
 
35
35
  form.section 'Account' do |section|
36
- section.button :change_email, icon: :email, action: push_email_controller
37
- section.button :change_password, icon: :lock, action: push_password_controller
36
+ section.button :change_email, action: push_email_controller
37
+ section.button :change_password, action: push_password_controller
38
38
  end
39
39
  end
40
40
 
@@ -118,7 +118,6 @@ end
118
118
 
119
119
  ``` ruby
120
120
  MotionForm.config do |config|
121
- config.icon_font = UIFont.fontWithName('dscovr', size: 14.0)
122
121
  config.section_header_color = UIColor.blueColor
123
122
  config.section_header_text_color = UIColor.whiteColor
124
123
  config.button_text_color = UIColor.redColor
@@ -9,8 +9,7 @@ class BaseCell < UITableViewCell
9
9
 
10
10
  def initWithStyle(style, reuseIdentifier: reuse_identifier)
11
11
  super.tap do |cell|
12
- cell.selectionStyle = UITableViewCellSelectionStyleNone
13
- cell.contentView.addSubview(text_field)
12
+ cell.selectionStyle = UITableViewCellSelectionStyleNone
14
13
  cell.selectedBackgroundView = selected_background_view
15
14
  end
16
15
  end
@@ -12,25 +12,38 @@ class ButtonCell < TextInputCell
12
12
  def initWithStyle(style, reuseIdentifier: reuse_identifier)
13
13
  super.tap do |cell|
14
14
  cell.selectionStyle = UITableViewCellSelectionStyleGray
15
+ cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator
15
16
  cell.text_field.enabled = false
16
17
 
17
- cell.add_right_view
18
+ cell.text_label.textColor = MotionForm.button_text_color
19
+
18
20
  cell.add_tap_recognizer
19
21
  end
20
22
  end
21
23
 
24
+ def setup_constraints
25
+ text_label.translatesAutoresizingMaskIntoConstraints = false
26
+ contentView.addSubview(text_label)
27
+
28
+ contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
29
+ 'H:|-margin-[label]-margin-|',
30
+ options: NSLayoutFormatAlignAllCenterY,
31
+ metrics: { 'margin' => 10 },
32
+ views: subviews_dict))
33
+
34
+ contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
35
+ 'V:|[label]|',
36
+ options: 0,
37
+ metrics: {},
38
+ views: subviews_dict))
39
+ end
40
+
22
41
  def add_tap_recognizer
23
42
  addGestureRecognizer(tap_recognizer)
24
43
  end
25
44
 
26
45
  def label=(label)
27
- text_field.attributedPlaceholder = build_highlighted_placeholder(label)
28
- end
29
-
30
- def build_highlighted_placeholder(label)
31
- NSAttributedString.alloc.initWithString(
32
- label,
33
- attributes: { NSForegroundColorAttributeName => MotionForm.button_text_color })
46
+ text_label.text = label
34
47
  end
35
48
 
36
49
  def tap_recognizer
@@ -41,25 +54,6 @@ class ButtonCell < TextInputCell
41
54
  post('FormCellWasTapped', notification_payload)
42
55
  end
43
56
 
44
- def add_right_view
45
- text_field.rightView = right_view
46
- text_field.rightViewMode = UITextFieldViewModeAlways
47
- end
48
-
49
- def accessory=(icon)
50
- right_view.name = icon
51
- end
52
-
53
- def right_view
54
- @right_view ||= IconView.alloc.init
55
- end
56
-
57
- def layoutSubviews
58
- super
59
-
60
- right_view.frame = [[size.width - 56, 0], [36, 43]]
61
- end
62
-
63
57
  def notification_payload
64
58
  { key: key }
65
59
  end
@@ -1,5 +1,4 @@
1
1
  motion_require './base_cell'
2
- motion_require '../views/icon_view'
3
2
 
4
3
  class TextFieldCell < BaseCell
5
4
  IDENTIFIER = 'TextFieldCell'
@@ -43,10 +42,6 @@ class TextFieldCell < BaseCell
43
42
  def secure=(secure)
44
43
  end
45
44
 
46
- def icon=(icon)
47
- left_view.name = icon
48
- end
49
-
50
45
  def text_view
51
46
  @text_view ||= SZTextView.alloc.init.tap do |text_view|
52
47
  text_view.font = UIFont.fontWithName('HelveticaNeue-Light', size: 14.0)
@@ -55,10 +50,6 @@ class TextFieldCell < BaseCell
55
50
  end
56
51
  alias_method :text_field, :text_view
57
52
 
58
- def left_view
59
- @left_view ||= IconView.alloc.init
60
- end
61
-
62
53
  def value
63
54
  text_view.text
64
55
  end
@@ -1,17 +1,48 @@
1
1
  motion_require './base_cell'
2
- motion_require '../views/icon_view'
3
2
 
4
3
  class TextInputCell < BaseCell
5
4
  IDENTIFIER = 'TextInputCell'
6
5
 
7
6
  def initWithStyle(style, reuseIdentifier: reuse_identifier)
8
7
  super.tap do |cell|
8
+ cell.setup_constraints
9
+
9
10
  cell.observe('ButtonCallbackWillFire', 'resign_textfield:')
10
11
  cell.observe('FormWillValidate', 'resign_textfield:')
11
12
  cell.observe('FormWillRender', 'resign_textfield:')
12
13
  end
13
14
  end
14
15
 
16
+ def setup_constraints
17
+ [text_label, text_field].each do |subview|
18
+ subview.translatesAutoresizingMaskIntoConstraints = false
19
+ contentView.addSubview(subview)
20
+ end
21
+
22
+ contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
23
+ 'H:|-margin-[label(100@1000)][input]-margin-|',
24
+ options: NSLayoutFormatAlignAllCenterY,
25
+ metrics: { 'margin' => 10 },
26
+ views: subviews_dict))
27
+
28
+ contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
29
+ 'V:|[label]|',
30
+ options: 0,
31
+ metrics: {},
32
+ views: subviews_dict))
33
+
34
+ contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
35
+ 'V:|[input]|',
36
+ options: 0,
37
+ metrics: {},
38
+ views: subviews_dict))
39
+ end
40
+
41
+ def subviews_dict
42
+ { 'label' => text_label,
43
+ 'input' => text_field }
44
+ end
45
+
15
46
  class << self
16
47
  def has_value?
17
48
  true
@@ -23,34 +54,35 @@ class TextInputCell < BaseCell
23
54
  end
24
55
 
25
56
  def label=(label)
26
- text_field.placeholder = label
57
+ text_label.text = label
27
58
  end
28
59
 
29
60
  def secure=(secure)
30
61
  text_field.secureTextEntry = secure
31
62
  end
32
63
 
33
- def icon=(icon)
34
- left_view.name = icon
64
+ def placeholder=(placeholder)
65
+ text_field.placeholder = placeholder
35
66
  end
36
67
 
37
68
  def text_field
38
69
  @text_field ||= UITextField.alloc.init.tap do |field|
39
70
  field.autocorrectionType = UITextAutocorrectionTypeNo
40
- field.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
41
71
  field.backgroundColor = UIColor.clearColor
42
72
  field.clearButtonMode = UITextFieldViewModeWhileEditing
43
73
  field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter
44
- field.leftView = left_view
45
- field.leftViewMode = UITextFieldViewModeAlways
46
- field.textColor = UIColor.grayColor
74
+ field.textColor = UIColor.darkGrayColor
75
+ field.font = UIFont.fontWithName('HelveticaNeue-Light', size: 16.0)
47
76
 
48
77
  field.delegate = self
49
78
  end
50
79
  end
51
80
 
52
- def left_view
53
- @left_view ||= IconView.alloc.init
81
+ def text_label
82
+ @text_label ||= UILabel.alloc.init.tap do |label|
83
+ label.textColor = UIColor.darkGrayColor
84
+ label.font = UIFont.fontWithName('HelveticaNeue-Light', size: 18.0)
85
+ end
54
86
  end
55
87
 
56
88
  def value
@@ -61,11 +93,6 @@ class TextInputCell < BaseCell
61
93
  text_field.text = value
62
94
  end
63
95
 
64
- def layoutSubviews
65
- text_field.frame = [[10, 0], [300, 43]]
66
- left_view.frame = [[0, 0], [36, 43]]
67
- end
68
-
69
96
  def textFieldDidBeginEditing(text_field)
70
97
  post('FormCellDidBeginEditing', notification_payload)
71
98
  end
@@ -7,7 +7,6 @@ module MotionForm
7
7
  def init
8
8
  initWithFrame(frame, style: UITableViewStylePlain).tap do |f|
9
9
  f.register_cells
10
- f.separatorStyle = UITableViewCellSeparatorStyleNone
11
10
  f.translatesAutoresizingMaskIntoConstraints = false
12
11
 
13
12
  f.dataSource = self
@@ -3,9 +3,7 @@ motion_require './cells/text_field_cell'
3
3
 
4
4
  module MotionForm
5
5
  class << self
6
- attr_writer :icon_font,
7
- :icon_mapper,
8
- :section_header_color,
6
+ attr_writer :section_header_color,
9
7
  :section_header_text_color,
10
8
  :section_header_font,
11
9
  :button_text_color
@@ -46,27 +44,19 @@ module MotionForm
46
44
  end
47
45
 
48
46
  def section_header_font
49
- @section_header_font || UIFont.fontWithName('HelveticaNeue-Bold', size: 14.0)
50
- end
51
-
52
- def icon_font
53
- @icon_font || UIFont.fontWithName('dscovr', size: 14.0)
54
- end
55
-
56
- def icon_mapper
57
- @icon_mapper || FontIconMapper
47
+ @section_header_font || UIFont.fontWithName('HelveticaNeue', size: 14.0)
58
48
  end
59
49
 
60
50
  def section_header_color
61
- @section_header_color || '#bac3c7'.to_color
51
+ @section_header_color || '#EFEFF4'.to_color
62
52
  end
63
53
 
64
54
  def section_header_text_color
65
- @section_header_text_color || '#eaf0f1'.to_color
55
+ @section_header_text_color || '#232323'.to_color
66
56
  end
67
57
 
68
58
  def button_text_color
69
- @button_text_color || '#bdc3c7'.to_color
59
+ @button_text_color || '#232323'.to_color
70
60
  end
71
61
  end
72
62
  end
@@ -1,11 +1,10 @@
1
1
  class BaseRow
2
- attr_reader :icon, :key, :label, :options
2
+ attr_reader :key, :label, :options
3
3
 
4
4
  def initialize(key, options)
5
5
  @key = key
6
6
  @options = options
7
7
 
8
- @icon = options.fetch(:icon, nil)
9
8
  @label = options.fetch(:label, key.to_s.titleize)
10
9
  @value = options.fetch(:value, nil)
11
10
  end
@@ -35,8 +34,8 @@ class BaseRow
35
34
  end
36
35
 
37
36
  def update_cell(cell)
38
- cell.key = key
39
- cell.label = label
40
- cell.icon = icon
37
+ cell.key = key
38
+ cell.label = label
39
+ cell.placeholder = options.fetch(:placeholder, nil)
41
40
  end
42
41
  end
@@ -2,23 +2,18 @@ motion_require '../cells/button_cell'
2
2
  motion_require './text_field_row'
3
3
 
4
4
  class ButtonRow < TextInputRow
5
- attr_reader :on_tap_callback, :accessory
5
+ attr_reader :on_tap_callback
6
6
 
7
7
  def initialize(key, options)
8
8
  super
9
9
 
10
10
  @on_tap_callback = options.fetch(:action, lambda {})
11
- @accessory = options.fetch(:accessory, nil)
12
11
  end
13
12
 
14
13
  def cell_type
15
14
  ButtonCell
16
15
  end
17
16
 
18
- def accessory
19
- options.fetch(:accessory, nil)
20
- end
21
-
22
17
  def listen
23
18
  observe('FormCellWasTapped', 'tapped:')
24
19
  end
@@ -34,6 +29,5 @@ class ButtonRow < TextInputRow
34
29
  def update_cell(cell)
35
30
  super
36
31
 
37
- cell.accessory = accessory
38
32
  end
39
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devon Blandin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-keyboard-avoiding
@@ -108,7 +108,6 @@ files:
108
108
  - lib/project/cells/text_field_cell.rb
109
109
  - lib/project/cells/text_input_cell.rb
110
110
  - lib/project/controllers/form_controller.rb
111
- - lib/project/font_icon_mapper.rb
112
111
  - lib/project/form/base.rb
113
112
  - lib/project/motion-form.rb
114
113
  - lib/project/rows/base_row.rb
@@ -117,7 +116,6 @@ files:
117
116
  - lib/project/rows/text_input_row.rb
118
117
  - lib/project/section/section.rb
119
118
  - lib/project/string.rb
120
- - lib/project/views/icon_view.rb
121
119
  - lib/project/views/padded_label.rb
122
120
  - lib/project/views/section_header_view.rb
123
121
  homepage: https://github.com/dblandin/motion-form
@@ -1,22 +0,0 @@
1
- module MotionForm
2
- module FontIconMapper
3
- class << self
4
- def call(icon)
5
- unicode(icon).hex.chr(Encoding::UTF_8)
6
- end
7
-
8
- def unicode(icon)
9
- mappings[icon] || ''
10
- end
11
-
12
- def mappings
13
- @mappings ||= begin
14
- path = NSBundle.mainBundle.pathForResource('icons', ofType:'json')
15
- data = NSData.dataWithContentsOfFile(path)
16
-
17
- NSJSONSerialization.JSONObjectWithData(data, options: 0, error: nil)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,18 +0,0 @@
1
- class IconView < UILabel
2
- attr_reader :name
3
-
4
- def init
5
- super.tap do |view|
6
- view.font = MotionForm.icon_font
7
- view.backgroundColor = UIColor.clearColor
8
- view.textColor = UIColor.grayColor
9
- view.textAlignment = NSTextAlignmentCenter
10
- end
11
- end
12
-
13
- def name=(name)
14
- @name = name
15
-
16
- self.text = MotionForm.icon_mapper.call(name)
17
- end
18
- end