Sha256: 9dbb1d3e694a94ba8da80b54f1841eee1e7c4ced6b9c8542b7d687a16a8a36b0

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

# This module adds search functionality, to Screen or TableSection
module MotionPrime
  module HasSearchBar
    def add_search_bar(options = {}, &block)
      target = options.delete(:target)

      search_bar = create_search_bar(options)
      search_bar.delegate = self

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

      @search_callback = block
      search_bar
    rescue
      puts "can't add search bar to #{self.class_name_without_kvo}"
    end

    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

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

    def searchBarSearchButtonClicked(search_bar)
      search_bar.resignFirstResponder
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motion-prime-0.3.3 motion-prime/helpers/has_search_bar.rb
motion-prime-0.3.2 motion-prime/helpers/has_search_bar.rb
motion-prime-0.3.1 motion-prime/helpers/has_search_bar.rb
motion-prime-0.3.0 motion-prime/helpers/has_search_bar.rb