Class: UnderOs::UI::Input
- Inherits:
-
View
- Object
- View
- UnderOs::UI::Input
show all
- Defined in:
- lib/under_os/ui/input.rb
Constant Summary
collapse
- KEYBOARDS =
{
default: UIKeyboardTypeDefault,
text: UIKeyboardTypeDefault,
ascii: UIKeyboardTypeASCIICapable,
numeric: UIKeyboardTypeNumbersAndPunctuation,
url: UIKeyboardTypeURL,
numbers: UIKeyboardTypeNumberPad,
phone: UIKeyboardTypePhonePad,
name: UIKeyboardTypeNamePhonePad,
email: UIKeyboardTypeEmailAddress,
decimal: UIKeyboardTypeDecimalPad,
twitter: UIKeyboardTypeTwitter,
search: UIKeyboardTypeWebSearch
}
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Input
Returns a new instance of Input.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/under_os/ui/input.rb', line 4
def initialize(options={})
super
self.type = options[:type] if options[:type]
self.name = options[:name] if options[:name]
self.value = options[:value] if options[:value]
self.placeholder = options[:placeholder] if options[:placeholder]
self.keyboard = options[:keyboard] if options[:keyboard]
self.disabled = true if options[:disabled]
@_.delegate = self if @_.respond_to?(:delegate=)
if @_.class == UITextField
@_.addTarget self, action: :handle_focus, forControlEvents:UIControlEventEditingDidBegin
@_.addTarget self, action: :handle_change, forControlEvents:UIControlEventEditingChanged
@_.addTarget self, action: :handle_blur, forControlEvents:UIControlEventEditingDidEnd
end
end
|
Instance Method Details
#blur ⇒ Object
117
118
119
|
# File 'lib/under_os/ui/input.rb', line 117
def blur
@_.resignFirstResponder
end
|
#disable ⇒ Object
105
106
107
|
# File 'lib/under_os/ui/input.rb', line 105
def disable
self.disabled = true
end
|
#disabled ⇒ Object
Also known as:
disabled?
95
96
97
|
# File 'lib/under_os/ui/input.rb', line 95
def disabled
! @_.isEnabled
end
|
#disabled=(value) ⇒ Object
101
102
103
|
# File 'lib/under_os/ui/input.rb', line 101
def disabled=(value)
@_.enabled = ! value
end
|
#enable ⇒ Object
109
110
111
|
# File 'lib/under_os/ui/input.rb', line 109
def enable
self.disabled = false
end
|
#focus ⇒ Object
113
114
115
|
# File 'lib/under_os/ui/input.rb', line 113
def focus
@_.becomeFirstResponder
end
|
#hide_keyboard ⇒ Object
75
76
77
78
|
# File 'lib/under_os/ui/input.rb', line 75
def hide_keyboard
puts "DEPRECATED: please use the `#blur` method instead of `#hide_keyboard`"
blur
end
|
#keyboard ⇒ Object
62
63
64
|
# File 'lib/under_os/ui/input.rb', line 62
def keyboard
KEYBOARDS.index(@_.keyboardType)
end
|
#keyboard=(keyboard) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/under_os/ui/input.rb', line 66
def keyboard=(keyboard)
keyboard = keyboard.to_sym if keyboard.is_a?(String)
keyboard = KEYBOARDS[keyboard] || keyboard
raise "Unknown keyboard type: #{keyboard}" if keyboard.is_a?(Symbol)
@_.keyboardType = keyboard
end
|
#name ⇒ Object
23
24
25
|
# File 'lib/under_os/ui/input.rb', line 23
def name
@name
end
|
#name=(text) ⇒ Object
27
28
29
|
# File 'lib/under_os/ui/input.rb', line 27
def name=(text)
@name = text
end
|
#placeholder ⇒ Object
39
40
41
|
# File 'lib/under_os/ui/input.rb', line 39
def placeholder
@_.placeholder
end
|
#placeholder=(value) ⇒ Object
43
44
45
|
# File 'lib/under_os/ui/input.rb', line 43
def placeholder=(value)
@_.placeholder = value
end
|
#textFieldShouldReturn(textField) ⇒ Object
123
124
125
|
# File 'lib/under_os/ui/input.rb', line 123
def textFieldShouldReturn(textField)
blur
end
|
#type ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/under_os/ui/input.rb', line 47
def type
if @_.respond_to?(:secureTextEntry) && @_.secureTextEntry
:password
else
keyboard == :default ? :text : keyboard
end
end
|
#type=(type) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/under_os/ui/input.rb', line 55
def type=(type)
case type.to_sym
when :password then @_.secureTextEntry = true
else self.keyboard = type
end
end
|
#value ⇒ Object
31
32
33
|
# File 'lib/under_os/ui/input.rb', line 31
def value
@_.text
end
|
#value=(value) ⇒ Object
35
36
37
|
# File 'lib/under_os/ui/input.rb', line 35
def value=(value)
@_.text = value
end
|