Class: UnderOs::UI::Select

Inherits:
Input show all
Defined in:
lib/under_os/ui/select.rb

Constant Summary

Constants inherited from Input

Input::KEYBOARDS

Constants included from Wrap

Wrap::INSTANCES_CACHE, Wrap::RAW_WRAPS_MAP, Wrap::WRAPS_TAGS_MAP

Instance Method Summary collapse

Methods inherited from Input

#blur, #disable, #disabled, #disabled=, #enable, #focus, #hide_keyboard, #keyboard, #keyboard=, #name, #name=, #placeholder, #placeholder=, #textFieldShouldReturn, #type, #type=

Methods inherited from View

#inspect

Methods included from Manipulation

#append, #clear, #insert, #insertTo, #prepend, #remove

Methods included from Traversing

#children, #empty?, #find, #first, #matches, #parent, #siblings

Methods included from Dimensions

#position, #position=, #size, #size=

Methods included from Animation

#animate, #fade_in, #fade_out, #highlight

Methods included from Commons

#data, #data=, #hidden, #id, #id=, #page, #tagName, #toggle, #visible

Methods included from Styles

#addClass, #className, #className=, #classNames, #classNames=, #hasClass, #radioClass, #removeClass, #repaint, #style, #style=, #toggleClass

Methods included from Events

#emit, #off, #on, #on=

Methods included from Wrap

included

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(options={})
  super

  self.options = options.delete(:options) if options[:options]
  @_.showsSelectionIndicator = true       if options[:lense]

  @_.dataSource = self
end

Instance Method Details

#hideObject



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

#optgroupsObject



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

#optionsObject



27
28
29
# File 'lib/under_os/ui/select.rb', line 27

def options
  optgroups.size == 1 ? optgroups[0] : optgroups
end

#options=(value) ⇒ Object



31
32
33
34
# File 'lib/under_os/ui/select.rb', line 31

def options=(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

#showObject



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

#valueObject



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