Module: MotionPrime::HasSearchBar
- Included in:
- Screen, TableSection
- Defined in:
- motion-prime/helpers/has_search_bar.rb
Instance Method Summary collapse
- #add_search_bar(options = {}, &block) ⇒ Object
- #create_search_bar(options = {}) ⇒ Object
- #dealloc ⇒ Object
- #searchBar(search_bar, textDidChange: text) ⇒ Object
- #searchBarSearchButtonClicked(search_bar) ⇒ Object
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 21 |
# File 'motion-prime/helpers/has_search_bar.rb', line 4 def ( = {}, &block) @_search_timeout = .delete(:timeout) target = .delete(:target) @_search_bar = () @_search_bar.setDelegate self if target target.addSubview @_search_bar elsif is_a?(TableSection) self.collection_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
30 31 32 33 34 35 36 37 |
# File 'motion-prime/helpers/has_search_bar.rb', line 30 def ( = {}) name = is_a?(TableSection) ? name : self.class_name_without_kvo.underscore screen = is_a?(TableSection) ? self.screen : self [:styles] ||= [] [:styles] += [:"base_search_bar", :"base_#{name}_search_bar"] screen.().view end |
#dealloc ⇒ Object
23 24 25 26 27 28 |
# File 'motion-prime/helpers/has_search_bar.rb', line 23 def dealloc BW::Reactor.cancel_timer(@_search_timer) if @_search_timer @_search_bar.try(:setDelegate, nil) @_search_bar = nil super end |
#searchBar(search_bar, textDidChange: text) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'motion-prime/helpers/has_search_bar.rb', line 39 def searchBar(, textDidChange: text) BW::Reactor.cancel_timer(@_search_timer) if @_search_timer if @_search_timeout @_search_timer = BW::Reactor.add_timer(@_search_timeout.to_f/1000, proc{ @search_callback.call(text) }.weak!) else @search_callback.call(text) end end |
#searchBarSearchButtonClicked(search_bar) ⇒ Object
48 49 50 51 52 |
# File 'motion-prime/helpers/has_search_bar.rb', line 48 def searchBarSearchButtonClicked() BW::Reactor.cancel_timer(@_search_timer) if @_search_timer @search_callback.call(.text) .resignFirstResponder end |