Class: MotionPrime::GridSection
- Inherits:
-
AbstractCollectionSection
- Object
- Section
- AbstractCollectionSection
- MotionPrime::GridSection
- Defined in:
- motion-prime/sections/grid.rb
Constant Summary collapse
- DEFAULT_GRID_SIZE =
3
Constants inherited from Section
Section::DEFAULT_CONTENT_HEIGHT, Section::KEYBOARD_HEIGHT_LANDSCAPE, Section::KEYBOARD_HEIGHT_PORTRAIT
Instance Attribute Summary
Attributes inherited from AbstractCollectionSection
#collection_element, #decelerating, #did_appear
Attributes inherited from Section
#elements, #model, #name, #options, #screen, #section_styles
Attributes included from DrawSectionMixin
#cached_draw_image, #container_element, #container_gesture_recognizers
Instance Method Summary collapse
- #cell_sections_for_group(section) ⇒ Object
- #collection_delegate ⇒ Object
- #collection_styles_base ⇒ Object
- #grid_element_options ⇒ Object
-
#grid_size ⇒ Object
Table View Delegate ———————.
-
#index_for_cell_section(section) ⇒ Object
Get index path for cell section.
- #number_of_cells_in_group(group) ⇒ Object
- #number_of_groups ⇒ Object
- #render_cell(index) ⇒ Object
- #render_collection ⇒ Object
Methods inherited from AbstractCollectionSection
#cell_for_index, #cell_name, #cell_section_by_index, #cell_section_styles, #collection_data, #collection_element_options, #collection_styles, #collection_view, #data, #dealloc, #fixed_collection_data, #height_for_index, #hide, #on_appear, #on_cell_render, #on_click, #refresh_if_needed, #reload, #reload_collection_data, #reload_data, #reset_collection_data, #scroll_view_did_end_decelerating, #scroll_view_did_end_dragging, #scroll_view_did_scroll, #scroll_view_will_begin_dragging, #show, #update_pull_to_refresh_after_scroll
Methods included from HasStyleChainBuilder
Methods inherited from Section
#add_element, after_element_render, #after_element_render, after_initialize, after_render, before_initialize, before_render, bind_keyboard_close, #bind_keyboard_events, #bring_to_front, container, #container_bounds, #container_height, #container_options, #create_elements, #current_input_view_height, #dealloc, #default_name, element, #element, #elements_options, #elements_to_draw, #elements_to_render, #hard_reload_section, #has_container_bounds?, #hide, #hide_keyboard, inherited, #initialize, #keyboard_will_hide, #keyboard_will_show, #on_keyboard_hide, #on_keyboard_show, #reload, #render, #render!, #render_container, #render_element?, #screen?, #show, #strong_references, #view
Methods included from DelegateMixin
#clear_delegated, #delegated_by
Methods included from DrawSectionMixin
#after_element_render, #before_element_render, #bind_gesture_on_container_for, #clear_gesture_for_receiver, #draw_in, #prerender_elements_for_state, #prerender_enabled?
Methods included from SectionWithContainerMixin
#container_view, #init_container_element, #load_container_with_elements
Methods included from FrameCalculatorMixin
Methods included from HasStyles
Methods included from HasClassFactory
#camelize_factory, #class_factory, #low_camelize_factory, #underscore_factory
Methods included from HasNormalizer
#debug_info, #element?, #normalize_object, #normalize_options, #normalize_value
Methods included from HasAuthorization
#api_client, #current_user, #reset_current_user, #user_signed_in?
Constructor Details
This class inherits a constructor from MotionPrime::Section
Instance Method Details
#cell_sections_for_group(section) ⇒ Object
57 58 59 |
# File 'motion-prime/sections/grid.rb', line 57 def cell_sections_for_group(section) data[section*grid_size, grid_size] end |
#collection_delegate ⇒ Object
26 27 28 |
# File 'motion-prime/sections/grid.rb', line 26 def collection_delegate @collection_delegate ||= CollectionDelegate.new(section: self) end |
#collection_styles_base ⇒ Object
22 23 24 |
# File 'motion-prime/sections/grid.rb', line 22 def collection_styles_base :base_collection end |
#grid_element_options ⇒ Object
30 31 32 33 34 |
# File 'motion-prime/sections/grid.rb', line 30 def .merge({ grid_size: grid_size }) end |
#grid_size ⇒ Object
Table View Delegate
64 65 66 |
# File 'motion-prime/sections/grid.rb', line 64 def grid_size self.class.grid_size || DEFAULT_GRID_SIZE end |
#index_for_cell_section(section) ⇒ Object
Get index path for cell section
15 16 17 18 19 20 |
# File 'motion-prime/sections/grid.rb', line 15 def index_for_cell_section(section) return unless item = @data.try(:index, section) group = item/grid_size row = cell_sections_for_group(group).index(section) NSIndexPath.indexPathForRow(row, inSection: group) end |
#number_of_cells_in_group(group) ⇒ Object
68 69 70 |
# File 'motion-prime/sections/grid.rb', line 68 def number_of_cells_in_group(group) cell_sections_for_group(group).count.to_i end |
#number_of_groups ⇒ Object
72 73 74 |
# File 'motion-prime/sections/grid.rb', line 72 def number_of_groups (data.count.to_f / grid_size).ceil end |
#render_cell(index) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'motion-prime/sections/grid.rb', line 40 def render_cell(index) collection_view.registerClass(MPCollectionCellWithSection, forCellWithReuseIdentifier: cell_name(index)) view = collection_view.dequeueReusableCellWithReuseIdentifier(cell_name(index), forIndexPath: index) section = cell_section_by_index(index) element = section.container_element || section.init_container_element((index)) unless view.section element.view = view screen. view, element..except(:parent_view) do section.render end on_cell_render(view, index) end view end |
#render_collection ⇒ Object
36 37 38 |
# File 'motion-prime/sections/grid.rb', line 36 def render_collection self.collection_element = screen.collection_view() end |