Sha256: d9e3ab09778fe1d5414c76ae2048787f621a625094945bdc831946df3914d92b

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

module MotionPrime
  class TableDelegate
    attr_accessor :table_section
    def initialize(options)
      self.table_section = options[:section].try(:weak_ref)
    end

    # def dealloc
    #   pp '@@ dealloc table_delegate'
    #   super
    # end

    def init_pull_to_refresh
      return unless block = table_section.class.pull_to_refresh_block
      table_section.add_pull_to_refresh do
        table_section.instance_eval(&block)
      end
    end

    def numberOfSectionsInTableView(table)
      table_section.number_of_sections(table)
    end

    def tableView(table, cellForRowAtIndexPath: index)
      curCallTime = Time.now.to_f
      curCallOffset = table.contentOffset.y
      if @prevCallTime
        timeDelta = curCallTime - @prevCallTime
        offsetDelta = curCallOffset - @prevCallOffset
        @deceleration_speed = offsetDelta/timeDelta
      end
      @prevCallTime = curCallTime
      @prevCallOffset = curCallOffset

      table_section.cell_for_index(table, index)
    end

    def tableView(table, numberOfRowsInSection: section)
      table_section.rows_for_section(section).try(:count).to_i
    end

    def tableView(table, heightForRowAtIndexPath: index)
      table_section.height_for_index(table, index)
    end

    def tableView(table, didSelectRowAtIndexPath:index)
      table_section.on_click(table, index)
    end

    def tableView(table, viewForHeaderInSection: section)
      table_section.view_for_header_in_section(table, section)
    end

    def tableView(table, heightForHeaderInSection: section)
      table_section.height_for_header_in_section(table, section)
    end

    def scrollViewWillBeginDragging(scroll)
      table_section.scroll_view_will_begin_dragging(scroll)
    end

    def scrollViewDidEndDecelerating(scroll)
      table_section.scroll_view_did_end_decelerating(scroll)
    end

    def scrollViewDidEndDragging(scroll, willDecelerate: will_decelerate)
      table_section.scroll_view_did_end_dragging(scroll, willDecelerate: will_decelerate)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motion-prime-0.5.5 motion-prime/sections/table/table_delegate.rb
motion-prime-0.5.4 motion-prime/sections/table/table_delegate.rb
motion-prime-0.5.3 motion-prime/sections/table/table_delegate.rb
motion-prime-0.5.2 motion-prime/sections/table/table_delegate.rb