Class: SugarCube::AnimationChain
- Defined in:
- lib/sugarcube/animation_chain.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<<(block) ⇒ Object
- #and_then(options = nil, &block) ⇒ Object
- #do_next ⇒ Object
-
#initialize ⇒ AnimationChain
constructor
A new instance of AnimationChain.
- #start ⇒ Object
- #wait(duration) ⇒ Object
Constructor Details
#initialize ⇒ AnimationChain
Returns a new instance of AnimationChain.
20 21 22 |
# File 'lib/sugarcube/animation_chain.rb', line 20 def initialize @blocks = [] end |
Class Method Details
.chains ⇒ Object
5 6 7 |
# File 'lib/sugarcube/animation_chain.rb', line 5 def chains @chains ||= [] end |
.start_chain(chain) ⇒ Object
9 10 11 |
# File 'lib/sugarcube/animation_chain.rb', line 9 def start_chain(chain) chains << chain end |
.stop_chain(chain) ⇒ Object
13 14 15 16 |
# File 'lib/sugarcube/animation_chain.rb', line 13 def stop_chain(chain) chains ||= [] @chains.delete(chain) end |
Instance Method Details
#<<(block) ⇒ Object
38 39 40 |
# File 'lib/sugarcube/animation_chain.rb', line 38 def << block and_then(&block) end |
#and_then(options = nil, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/sugarcube/animation_chain.rb', line 28 def and_then(=nil, &block) if = .dup else = {} end @blocks << [, block] self end |
#do_next ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sugarcube/animation_chain.rb', line 42 def do_next return nil if @block_index >= @blocks.length , block = @blocks[@block_index] @after_block = ->(completed){ self.do_next || AnimationChain.stop_chain(self) } [:after] = @after_block UIView.animate() { block.call @block_index += 1 } true end |
#start ⇒ Object
58 59 60 61 62 |
# File 'lib/sugarcube/animation_chain.rb', line 58 def start AnimationChain.start_chain(self) @block_index = 0 do_next end |
#wait(duration) ⇒ Object
24 25 26 |
# File 'lib/sugarcube/animation_chain.rb', line 24 def wait(duration) and_then(duration: duration) {} end |