Sha256: e5c76a673e571ee4758360f92d9944d8040a123a2a4dbd416afaa0ac6567de85

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

module MotionPrime
  module CellSectionMixin
    extend ::MotionSupport::Concern

    attr_writer :table
    attr_reader :pending_display

    included do
      class_attribute :custom_cell_name
    end

    def table
      @table ||= options[:table].try(:weak_ref)
    end

    def section_styles
      @section_styles ||= table.try(:cell_styles, self) || {}
    end

    def cell_type
      @cell_type ||= begin
        self.is_a?(BaseFieldSection) ? :field : :cell
      end
    end

    def cell_name
      self.class.custom_cell_name || begin
        return name unless table
        table_name = table.name.gsub('_table', '')
        name.gsub("#{table_name}_", '')
      end
    end

    def container_bounds
      @container_bounds ||= CGRectMake(0, 0, table.table_view.bounds.size.width, container_height)
    end

    def init_container_element(options = {})
      @container_element ||= begin
        options.merge!({
          screen: screen,
          section: self.weak_ref,
          has_drawn_content: true
        })
        options[:styles] ||= []
        options[:styles] = [:"#{table.name}_first_cell"] if table.data.first == self
        options[:styles] = [:"#{table.name}_last_cell"] if table.data.last == self
        MotionPrime::BaseElement.factory(:table_view_cell, options)
      end
    end

    def load_container_element(options = {})
      init_container_element(options)
      load_elements
      @container_element.compute_options! unless @container_element.computed_options
      if respond_to?(:prerender_elements_for_state) && prerender_enabled?
        prerender_elements_for_state(:normal)
      end
    end

    def pending_display!
      @pending_display = true
      display unless table.decelerating
    end

    def display
      @pending_display = false
      container_view.setNeedsDisplay
    end

    module ClassMethods
      def set_cell_name(value)
        self.custom_cell_name = value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-prime-0.4.5 motion-prime/sections/_cell_section_mixin.rb