Class: UnderOs::UI::Select
- Inherits:
-
Input
- Object
- Input
- UnderOs::UI::Select
- Defined in:
- lib/under_os/ui/select.rb
Instance Method Summary collapse
- #hide ⇒ Object
-
#initialize(options = {}) ⇒ Select
constructor
A new instance of Select.
-
#numberOfComponentsInPickerView(picker) ⇒ Object
UIPickerView delegate.
- #optgroups ⇒ Object
- #optgroups=(list) ⇒ Object
- #options ⇒ Object
- #options=(value) ⇒ Object
- #pickerView(picker, didSelectRow: index, inComponent: group) ⇒ Object
- #show ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Select
Returns a new instance of Select.
4 5 6 7 8 9 10 11 |
# File 'lib/under_os/ui/select.rb', line 4 def initialize(={}) super self. = .delete(:options) if [:options] @_.showsSelectionIndicator = true if [:lense] @_.dataSource = self end |
Instance Method Details
#hide ⇒ Object
68 69 70 71 72 |
# File 'lib/under_os/ui/select.rb', line 68 def hide animate bottom: -size.y, complete: -> { style.display = :none } end |
#numberOfComponentsInPickerView(picker) ⇒ Object
UIPickerView delegate
77 78 79 |
# File 'lib/under_os/ui/select.rb', line 77 def numberOfComponentsInPickerView(picker) optgroups.size end |
#optgroups ⇒ Object
13 14 15 |
# File 'lib/under_os/ui/select.rb', line 13 def optgroups @optgroups ||= [{}] end |
#optgroups=(list) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/under_os/ui/select.rb', line 17 def optgroups=(list) @optgroups = list.map do |hash| {}.tap do |clean_hash| hash.each do |key, value| clean_hash[key.to_s] = value if key && value end end end end |
#options ⇒ Object
27 28 29 |
# File 'lib/under_os/ui/select.rb', line 27 def optgroups.size == 1 ? optgroups[0] : optgroups end |
#options=(value) ⇒ Object
31 32 33 34 |
# File 'lib/under_os/ui/select.rb', line 31 def (value) self.optgroups = value.is_a?(Array) ? value : [value] @_.reloadAllComponents end |
#pickerView(picker, didSelectRow: index, inComponent: group) ⇒ Object
81 82 83 |
# File 'lib/under_os/ui/select.rb', line 81 def pickerView(picker, numberOfRowsInComponent: group) optgroups[group].size end |
#show ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/under_os/ui/select.rb', line 58 def show page.find('select').each do |select| select.hide if select.visible && select != self end self.style = {bottom: -size.y, display: :block} animate bottom: 0 end |
#value ⇒ Object
36 37 38 39 |
# File 'lib/under_os/ui/select.rb', line 36 def value @value ||= [] optgroups.size == 1 ? @value[0] : @value end |
#value=(value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/under_os/ui/select.rb', line 41 def value=(value) prev_val = @value @value = Array(value).map(&:to_s) handle_change if @value != prev_val @value.each_with_index do |value, group| i = 0; optgroups[group].each do |v, label| if value == v @_.selectRow i, inComponent: group, animated: false else i += 1 end end end end |