Sha256: d2c4c9086e9852f113ddb951c6e0c618aaac03ac3aed44bcd6b08f6054fed5ea

Contents?: true

Size: 830 Bytes

Versions: 8

Compression:

Stored size: 830 Bytes

Contents

# This module adds search functionality, to Screen or TableSection
module MotionPrime
  module HasSearchBar
    def add_search_bar(&block)
      search_bar = create_search_bar
      search_bar.delegate = self
      self.table_view.tableHeaderView = search_bar if is_a?(TableSection)
      @search_callback = block
    rescue
      puts "can't add search bar to #{self.class.name}"
    end

    def create_search_bar
      name = is_a?(TableSection) ? name : self.class.name.underscore
      screen = is_a?(TableSection) ? self.screen : self
      screen.search_bar(styles: [:"base_search_bar", :"#{name}_search_bar"]).view
    end

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

    def searchBarSearchButtonClicked(search_bar)
      search_bar.resignFirstResponder
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
motion-prime-0.2.1 motion-prime/helpers/has_search_bar.rb
motion-prime-0.2.0 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.7 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.6 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.5 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.4 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.3 motion-prime/helpers/has_search_bar.rb
motion-prime-0.1.2 motion-prime/helpers/has_search_bar.rb