Module: MotionPrime::HasSearchBar

Included in:
TableSection
Defined in:
motion-prime/helpers/has_search_bar.rb

Instance Method Summary collapse

Instance Method Details

#add_search_bar(options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'motion-prime/helpers/has_search_bar.rb', line 4

def add_search_bar(options = {}, &block)
  target = options.delete(:target)

  @_search_bar = create_search_bar(options)
  @_search_bar.setDelegate self

  if target
    target.addSubview @_search_bar
  elsif is_a?(TableSection)
    self.table_view.tableHeaderView = @_search_bar
  end

  @search_callback = block
  @_search_bar
rescue
  NSLog("can't add search bar to #{self.class_name_without_kvo}")
end

#create_search_bar(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'motion-prime/helpers/has_search_bar.rb', line 28

def create_search_bar(options = {})
  name = is_a?(TableSection) ? name : self.class_name_without_kvo.underscore
  screen = is_a?(TableSection) ? self.screen : self
  options[:styles] ||= []
  options[:styles] += [:"base_search_bar", :"base_#{name}_search_bar"]

  screen.search_bar(options).view
end

#deallocObject



22
23
24
25
26
# File 'motion-prime/helpers/has_search_bar.rb', line 22

def dealloc
  @_search_bar.try(:setDelegate, nil)
  @_search_bar = nil
  super
end

#searchBar(search_bar, textDidChange: text) ⇒ Object



37
38
39
# File 'motion-prime/helpers/has_search_bar.rb', line 37

def searchBar(search_bar, textDidChange: text)
  @search_callback.call(text)
end

#searchBarSearchButtonClicked(search_bar) ⇒ Object



41
42
43
# File 'motion-prime/helpers/has_search_bar.rb', line 41

def searchBarSearchButtonClicked(search_bar)
  search_bar.resignFirstResponder
end