Sha256: 2ff3ae2368fcdeb7fbe9a6a55dc602a3f940f1a300538d49ac60e68c6dbfa384

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

module MotionPrime
  class CollectionDelegate
    include DelegateMixin
    attr_accessor :collection_section

    def initialize(options)
      self.collection_section = options[:section].try(:weak_ref)
      @section_instance = collection_section.to_s
    end

    # def dealloc
    #   pp 'Deallocating collection_delegate for ', @section_instance
    #   super
    # end

    def numberOfSectionsInCollectionView(table)
      collection_section.number_of_groups
    end

    def collectionView(table, cellForItemAtIndexPath: index)
      cur_call_time = Time.now.to_f
      cur_call_offset = table.contentOffset.y
      if @prev_call_time
        time_delta = cur_call_time - @prev_call_time
        offset_delta = cur_call_offset - @prev_call_offset
        @deceleration_speed = offset_delta/time_delta
      end
      @prev_call_time = cur_call_time
      @prev_call_offset = cur_call_offset

      collection_section.cell_for_index(index)
    end

    def collectionView(table, numberOfItemsInSection: group)
      collection_section.number_of_cells_in_group(group)
    end

    def collectionView(table, heightForItemAtIndexPath: index)
      collection_section.height_for_index(index)
    end

    def collectionView(table, didSelectItemAtIndexPath:index)
      collection_section.on_click(index)
    end

    def scrollViewDidScroll(scroll)
      collection_section.scroll_view_did_scroll(scroll)
    end

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
motion-prime-1.0.3 motion-prime/sections/collection/collection_delegate.rb
motion-prime-1.0.2 motion-prime/sections/collection/collection_delegate.rb
motion-prime-1.0.1 motion-prime/sections/collection/collection_delegate.rb
motion-prime-1.0.0 motion-prime/sections/collection/collection_delegate.rb
motion-prime-0.9.9.2 motion-prime/sections/collection/collection_delegate.rb
motion-prime-0.9.9.1 motion-prime/sections/collection/collection_delegate.rb