Class: MotionPrime::TabbedSection

Inherits:
Section
  • Object
show all
Includes:
HasNormalizer
Defined in:
motion-prime/sections/tabbed.rb

Constant Summary

Constants inherited from Section

Section::DEFAULT_CONTENT_HEIGHT, Section::KEYBOARD_HEIGHT_LANDSCAPE, Section::KEYBOARD_HEIGHT_PORTRAIT

Instance Attribute Summary collapse

Attributes inherited from Section

#elements, #model, #name, #options, #screen, #section_styles

Attributes included from DrawSectionMixin

#cached_draw_image, #container_element, #container_gesture_recognizers

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasNormalizer

#normalize_object, #normalize_options

Methods inherited from Section

#add_element, after_initialize, after_render, before_initialize, before_render, bind_keyboard_close, #bind_keyboard_events, #cell, 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, #has_container_bounds?, #hide, #hide_keyboard, #initialize, #keyboard_will_hide, #keyboard_will_show, #on_keyboard_hide, #on_keyboard_show, #reload, #reload_section, #render, #render!, #render_container, #render_element?, #screen?, #show, #strong_references, #view

Methods included from DelegateMixin

#clear_delegated, #delegated_by

Methods included from DrawSectionMixin

#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

#calculate_frome_for

Methods included from HasStyles

#prepare_gradient

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory

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 Attribute Details

#tab_pagesObject

Returns the value of attribute tab_pages.



16
17
18
# File 'motion-prime/sections/tabbed.rb', line 16

def tab_pages
  @tab_pages
end

Class Method Details

.inherited(subclass) ⇒ Object



88
89
90
91
92
93
# File 'motion-prime/sections/tabbed.rb', line 88

def inherited(subclass)
  super
  subclass.tabs_options = self.tabs_options.try(:clone)
  subclass.tabs_default = self.tabs_default.try(:clone)
  subclass.tabs_indexes = self.tabs_indexes.try(:clone)
end

.tab(id, options = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'motion-prime/sections/tabbed.rb', line 95

def tab(id, options = {})
  options[:name] ||= id.to_s.titleize
  options[:id] = id

  self.tabs_indexes ||= {}
  self.tabs_indexes[id] = tabs_indexes.length
  self.tabs_default = tabs_indexes.length - 1 if options[:default]

  self.tabs_options ||= {}
  self.tabs_options[id] = options
end

Instance Method Details

#disable_at(index) ⇒ Object

Make tab button disabled by index

Parameters:

  • Fixnum

    index



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

def disable_at(index)
  toggle_at(index, false)
end

#enable_at(index) ⇒ Object

Make tab button enabled by index

Parameters:

  • Fixnum

    index



44
45
46
# File 'motion-prime/sections/tabbed.rb', line 44

def enable_at(index)
  toggle_at(index, true)
end

#on_click(*control) ⇒ Object

on click to segment tab

Parameters:

  • UISegemtedControl

    control



60
61
62
# File 'motion-prime/sections/tabbed.rb', line 60

def on_click(*control)
  show_at_index(control.selectedSegment)
end

#set_title(key, title) ⇒ Object



82
83
84
85
# File 'motion-prime/sections/tabbed.rb', line 82

def set_title(key, title)
  id = self.class.tabs_indexes[key]
  view(:control).setTitle(title, forSegmentAtIndex: id)
end

#show_at_index(index) ⇒ Object



64
65
66
67
68
69
70
# File 'motion-prime/sections/tabbed.rb', line 64

def show_at_index(index)
  @tab_pages.each_with_index do |page, i|
    page.hide if index != i
  end
  view(:control).setSelectedSegmentIndex index
  @tab_pages[index].show
end

#show_by_key(key) ⇒ Object



72
73
74
75
# File 'motion-prime/sections/tabbed.rb', line 72

def show_by_key(key)
  id = self.class.tabs_indexes[key]
  show_at_index(id)
end

#tab_control_itemsObject



28
29
30
# File 'motion-prime/sections/tabbed.rb', line 28

def tab_control_items
  @tab_control_items ||= tab_options.values.map{ |o| o[:name] }
end

#tab_defaultObject



32
33
34
# File 'motion-prime/sections/tabbed.rb', line 32

def tab_default
  @tab_default ||= self.class.tabs_default || 0
end

#tab_optionsObject



24
25
26
# File 'motion-prime/sections/tabbed.rb', line 24

def tab_options
  @tab_options ||= normalize_options(self.class.tabs_options.clone)
end

#tab_page(key) ⇒ Object



77
78
79
80
# File 'motion-prime/sections/tabbed.rb', line 77

def tab_page(key)
  id = self.class.tabs_indexes[key]
  tab_pages[id]
end

#toggle_at(index, value) ⇒ Object

Toggle tab button activity by index

Parameters:

  • index (Fixnum, String)

    or tab id

  • Boolean

    value



51
52
53
54
55
56
# File 'motion-prime/sections/tabbed.rb', line 51

def toggle_at(index, value)
  if index.is_a?(Symbol)
    index = self.class.tabs_indexes[index]
  end
  view(:control).setEnabled value, forSegmentAtIndex: index
end