Class: MotionPrime::PageViewDelegate

Inherits:
Object
  • Object
show all
Includes:
DelegateMixin
Defined in:
motion-prime/sections/page_view/page_view_delegate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DelegateMixin

#clear_delegated, #delegated_by

Constructor Details

#initialize(options) ⇒ PageViewDelegate

Returns a new instance of PageViewDelegate.



6
7
8
9
10
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 6

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

Instance Attribute Details

#collection_sectionObject

Returns the value of attribute collection_section.



4
5
6
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 4

def collection_section
  @collection_section
end

Instance Method Details

#dataObject

def dealloc

pp 'Deallocating page_view_delegate for ', @section_instance
super

end



17
18
19
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 17

def data
  collection_section.data
end

#fetch_item(index) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 21

def fetch_item(index)
  if @view_controllers[index]
    @view_controllers[index]
  else
    controller = MotionPrime::Screen.new
    section = data[index]
    section.screen = controller.weak_ref
    controller.set_section :main, instance: section
    @view_controllers[index] = controller
  end
end

#indexOfViewController(viewController) ⇒ Object



38
39
40
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 38

def indexOfViewController(viewController)
  @view_controllers.key(viewController)
end

#pageViewController(pvc, spineLocationForInterfaceOrientation: orientation) ⇒ Object



42
43
44
45
46
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 42

def pageViewController(pvc, viewControllerBeforeViewController:vc)
  index = indexOfViewController(vc)
  return if !index || index <= 0
  fetch_item(index - 1)
end

#presentationCountForPageViewController(controller) ⇒ Object



55
56
57
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 55

def presentationCountForPageViewController(controller)
  data.size
end

#viewControllerAtIndex(index, storyboard: storyboard) ⇒ Object



33
34
35
36
# File 'motion-prime/sections/page_view/page_view_delegate.rb', line 33

def viewControllerAtIndex(index, storyboard:storyboard)
  return nil if data.length == 0 || index >= data.size
  fetch_item(index)
end