class UnderOs::UI::Animation::Animation

Constants

CURVES
FX_QUEUE

Public Class Methods

new(view, options, &block) click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 45
def initialize(view, options, &block)
  @view    = view
  @options = options
  @block   = block

  @options = {duration: options} if options.is_a?(Numeric)

  @options[:schedule] == false ? run : schedule
end

Public Instance Methods

delay() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 81
def delay
  @options[:delay] || 0.0
end
duration() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 77
def duration
  @options[:duration] || 0.25
end
options() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 85
def options
  options = CURVES[@options[:curve]] || @options[:curve] || UIViewAnimationCurveEaseOut
  options = options | UIViewAnimationOptionAutoreverse if @options[:autoreverse]
  options = options | UIViewAnimationOptionRepeat      if @options[:repeat]
  options | UIViewAnimationOptionAllowUserInteraction
end
queue() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 55
def queue
  FX_QUEUE[@view] ||= []
end
run() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 67
def run
  @view.emit('animation:start')

  UIView.animateWithDuration duration,
                      delay: delay,
                    options: options,
                 animations: ->{ @block.call },
                 completion: ->(finished){ run_next }
end
run_next() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 92
def run_next
  @view.emit('animation:finished')
  @options[:complete].call if @options[:complete]

  if next_fx = queue.shift
    next_fx.run
  end
end
schedule() click to toggle source
# File lib/under_os/ui/utils/animation.rb, line 59
def schedule
  if queue.empty?
    run
  else
    queue << self
  end
end