Class: MotionWizard::WizardViewController

Inherits:
UIViewController
  • Object
show all
Defined in:
lib/motion-wizard/controllers/wizard_view_controller.rb

Constant Summary collapse

DEFAULT_NAVIGATION_BAR_HEIGHT =
44

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_viewObject (readonly)

Returns the value of attribute content_view.



3
4
5
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 3

def content_view
  @content_view
end

Returns the value of attribute navigation_bar_view.



3
4
5
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 3

def navigation_bar_view
  @navigation_bar_view
end

#wizard_dataObject (readonly)

Returns the value of attribute wizard_data.



3
4
5
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 3

def wizard_data
  @wizard_data
end

Class Method Details

.backward_animation_strategy(animation_strategy_class) ⇒ Object



15
16
17
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 15

def self.backward_animation_strategy(animation_strategy_class)
  @_backward_animation_strategy_class = animation_strategy_class
end

.forward_animation_strategy(animation_strategy_class) ⇒ Object



11
12
13
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 11

def self.forward_animation_strategy(animation_strategy_class)
  @_forward_animation_strategy_class = animation_strategy_class
end

.index_item_view_class(index_item_view_class) ⇒ Object



19
20
21
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 19

def self.index_item_view_class(index_item_view_class)
  @_index_item_view_class = index_item_view_class
end

.steps(*steps) ⇒ Object



7
8
9
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 7

def self.steps(*steps)
  @_wizard_steps = steps
end

Instance Method Details

#add_new_step_view(animation_strategy) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 58

def add_new_step_view(animation_strategy)
  @current_view_controller = get_current_step_view_controller
  self.addChildViewController(@current_view_controller)
  @content_view.addSubview(@current_view_controller.view)

  @current_view_controller.view.origin = [0,0]
  animation_strategy.show_view(@current_view_controller.view)
  navigation_bar_view.select(@current_step)
end

#change_step_view(animation_strategy_klass) ⇒ Object



123
124
125
126
127
128
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 123

def change_step_view(animation_strategy_klass)
  animation_strategy = animation_strategy_klass.new
  remove_current_step_view(animation_strategy)
  add_new_step_view(animation_strategy)
  animation_strategy.animate
end

#create_index_item_at(index) ⇒ Object



130
131
132
133
134
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 130

def create_index_item_at(index)
  index_item = @index_item_view_class.alloc.init
  index_item.label.text = "%02d" % (index+1)
  index_item
end

#finish(data = {}) ⇒ Object



118
119
120
121
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 118

def finish(data = {})
  @wizard_data.merge! data
  self.when_finished
end

#get_current_step_view_controllerObject



68
69
70
71
72
73
74
75
76
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 68

def get_current_step_view_controller
  @steps_controllers[@current_step] ||= begin
    new_view_controller = @steps_controllers_classes[@current_step].alloc.init
    new_view_controller.extend(MotionWizard::ContentController)
    new_view_controller.wizard_view_controller = self
    new_view_controller.view.size = @content_view.size
    new_view_controller
  end
end

#go_to_step(step_number, data = {}) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 110

def go_to_step(step_number, data = {})
  @wizard_data.merge! data
  animation_klass = @current_step > step_number ? @backward_animation_strategy_class : @forward_animation_strategy_class
  @current_step = step_number
  change_step_view(animation_klass)
  self
end

#initObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 23

def init
  super
  @steps_controllers_classes = self.class.instance_variable_get(:@_wizard_steps) || []
  @forward_animation_strategy_class = self.class.instance_variable_get(:@_forward_animation_strategy_class) || AnimationStrategy::RightToLeft
  @backward_animation_strategy_class = self.class.instance_variable_get(:@_backward_animation_strategy_class) || AnimationStrategy::LeftToRight
  @index_item_view_class = self.class.instance_variable_get(:@_index_item_view_class) || IndexItem
  @current_step = 0
  @wizard_data = {}
  @steps_controllers = []
  self
end

#next(data = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 90

def next(data = {})
  @wizard_data.merge! data
  @current_step+=1
  if @current_step >= number_of_steps
    @current_step = number_of_steps - 1
    self.finish
    return
  end
  change_step_view(@forward_animation_strategy_class)
  self
end

#number_of_stepsObject



86
87
88
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 86

def number_of_steps
  @steps_controllers_classes.size
end

#previous(data = {}) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 102

def previous(data = {})
  @wizard_data.merge! data
  @current_step-=1
  return if @current_step < 0
  change_step_view(@backward_animation_strategy_class)
  self
end

#remove_current_step_view(animation_strategy) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 78

def remove_current_step_view(animation_strategy)
  current_local_view = @current_view_controller
  animation_strategy.hide_view(@current_view_controller.view) do |view|
    view.removeFromSuperview
    current_local_view.removeFromParentViewController
  end
end

#reset!Object



51
52
53
54
55
56
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 51

def reset!
  @wizard_data = {}
  @steps_controllers = []
  @navigation_bar_view.reset!
  navigation_bar_view.select(@current_step)
end

#setup_index_item_at(index_item, index) ⇒ Object



136
137
138
139
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 136

def setup_index_item_at(index_item, index)
  index_item.label_wrapper.size = index_item.size
  index_item.label.size = index_item.size
end

#viewDidLoadObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 35

def viewDidLoad
  super

  @content_view = UIView.alloc.init
  @content_view.origin = [0,0]
  @content_view.size = self.view.size
  self.view.addSubview(@content_view)

  @navigation_bar_view = WizardNavigationBar.alloc.init_with_number_of_steps(number_of_steps, self)
  @navigation_bar_view.origin = [0,0]
  @navigation_bar_view.size = [self.view.size.width, DEFAULT_NAVIGATION_BAR_HEIGHT]
  self.view.addSubview(navigation_bar_view)

  add_new_step_view(AnimationStrategy::None.new)
end

#when_finishedObject



141
# File 'lib/motion-wizard/controllers/wizard_view_controller.rb', line 141

def when_finished;end