Class: Formotion::RowType::TextRow
- Inherits:
-
Base
show all
- Includes:
- BW::KVO
- Defined in:
- lib/formotion/row_type/text_row.rb
Constant Summary
collapse
- TEXT_VIEW_TAG =
1000
Instance Attribute Summary collapse
Attributes inherited from Base
#row, #tableView
Instance Method Summary
collapse
Methods inherited from Base
#_on_select, #after_build, #after_delete, #break_with_semaphore, #button?, #cellEditingStyle, #cell_style, #delete_row, field_buffer, #indentWhileEditing?, #initialize, #input_accessory_view, #on_delete, #update_cell, #with_semaphore
Instance Attribute Details
Returns the value of attribute field.
10
11
12
|
# File 'lib/formotion/row_type/text_row.rb', line 10
def field
@field
end
|
Instance Method Details
#build_cell(cell) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/formotion/row_type/text_row.rb', line 12
def build_cell(cell)
cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleBlue
@field = UITextView.alloc.initWithFrame(CGRectZero)
field.backgroundColor = UIColor.clearColor
field.editable = true
field.tag = TEXT_VIEW_TAG
field.text = row.value
field.returnKeyType = row.return_key || UIReturnKeyDefault
field.autocapitalizationType = row.auto_capitalization if row.auto_capitalization
field.autocorrectionType = row.auto_correction if row.auto_correction
field.inputAccessoryView = input_accessory_view(row.input_accessory) if row.input_accessory
field.font = BW::Font.new(row.font) if row.font
field.placeholder = row.placeholder
field.enabled = row.editable?
field.on_begin do |text_field|
row.on_begin_callback && row.on_begin_callback.call
@tap_gesture.enabled = true
end
field.should_begin? do |text_field|
row.section.form.active_row = row
true
end
observe(self.row, "value") do |old_value, new_value|
break_with_semaphore do
field.text = row.value
end
end
field.on_change do |text_field|
break_with_semaphore do
row.value = text_field.text
end
end
field.on_end do |text_field|
@tap_gesture.enabled = false
end
@tap_gesture = UITapGestureRecognizer.alloc.initWithTarget self, action:'dismissKeyboard'
@tap_gesture.enabled = false
cell.addGestureRecognizer @tap_gesture
cell.swizzle(:layoutSubviews) do
def layoutSubviews
old_layoutSubviews
formotion_field = self.viewWithTag(TEXT_VIEW_TAG)
formotion_field.sizeToFit
field_frame = formotion_field.frame
field_frame.origin.y = 10
field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer
field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer
field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer
formotion_field.frame = field_frame
end
end
cell.addSubview(field)
field
end
|
#dismissKeyboard ⇒ Object
89
90
91
|
# File 'lib/formotion/row_type/text_row.rb', line 89
def dismissKeyboard
field.resignFirstResponder
end
|
#done_editing ⇒ Object
93
94
95
96
|
# File 'lib/formotion/row_type/text_row.rb', line 93
def done_editing
dismissKeyboard
self.row.done_action.call unless self.row.done_action.nil?
end
|
#on_select(tableView, tableViewDelegate) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/formotion/row_type/text_row.rb', line 82
def on_select(tableView, tableViewDelegate)
if !row.editable?
return
end
field.becomeFirstResponder
end
|