Module: ProMotion::Collection

Includes:
CollectionBuilder, Styling, Table::Utils
Included in:
CollectionScreen
Defined in:
lib/ProMotion/collection/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CollectionBuilder

#create_collection_cell, #on_cell_created, #on_cell_reused, #trigger_action

Methods included from Table::Utils

#array_all_members_of?, #index_path_to_section_index

Methods included from Styling

#add, #add_to, #camelize, #closest_parent, #content_height, #content_max, #content_width, #hex_color, #remove, #rgb_color, #rgba_color, #set_attribute, #set_attributes, #view_or_self

Instance Attribute Details

#promotion_collection_dataObject (readonly)

Returns the value of attribute promotion_collection_data.



7
8
9
# File 'lib/ProMotion/collection/collection.rb', line 7

def promotion_collection_data
  @promotion_collection_data
end

Instance Method Details

#cell_at(args = {}) ⇒ Object

Returns the data cell



42
43
44
# File 'lib/ProMotion/collection/collection.rb', line 42

def cell_at(args = {})
  self.promotion_collection_data.cell(args)
end

#check_collection_dataObject



33
34
35
# File 'lib/ProMotion/collection/collection.rb', line 33

def check_collection_data
  mp("Missing #collection_data method in CollectionScreen #{self.class.to_s}.", force_color: :red) unless self.respond_to?(:collection_data)
end

#collection_viewObject



9
10
11
# File 'lib/ProMotion/collection/collection.rb', line 9

def collection_view
  self.collectionView
end

#collectionView(_, layout: view_layout, sizeForItemAtIndexPath: index_path) ⇒ Object

UICollectionViewDelegateFlowLayout ##



66
67
68
# File 'lib/ProMotion/collection/collection.rb', line 66

def collectionView(_, numberOfItemsInSection: section)
  self.promotion_collection_data.section_length(section)
end

#numberOfSectionsInCollectionView(_) ⇒ Object



70
71
72
# File 'lib/ProMotion/collection/collection.rb', line 70

def numberOfSectionsInCollectionView(_)
  self.promotion_collection_data.sections.length
end

#reload_dataObject Also known as: update_collection_data



57
58
59
# File 'lib/ProMotion/collection/collection.rb', line 57

def reload_data
  update_collection_view_data(collection_data)
end

#screen_setupObject



13
14
15
# File 'lib/ProMotion/collection/collection.rb', line 13

def screen_setup
  check_collection_data
end

#set_up_register_classObject



24
25
26
27
28
29
30
31
# File 'lib/ProMotion/collection/collection.rb', line 24

def set_up_register_class
  collection_view.registerClass(PM::CollectionViewCell, forCellWithReuseIdentifier: PM::CollectionViewCell::KIdentifier)
  if self.class.get_cell_classes
    self.class.get_cell_classes.each do |identifier, klass|
      collection_view.registerClass(klass, forCellWithReuseIdentifier: identifier.to_s)
    end
  end
end

#update_collection_view_data(data, args = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/ProMotion/collection/collection.rb', line 46

def update_collection_view_data(data, args = {})
  self.promotion_collection_data.data = data
  if args[:index_paths]
    collection_view.reloadItemsAtIndexPaths(Array(args[:index_paths]))
  elsif args[:sections]
    collection_view.reloadSections(args[:sections])
  else
    collection_view.reloadData
  end
end

#viewDidLoadObject

Override viewDidLoad here to register cell classes here. Calling it from ‘screen_setup` cause `on_load` to be called twice



19
20
21
22
# File 'lib/ProMotion/collection/collection.rb', line 19

def viewDidLoad
  super
  set_up_register_class
end