Class: UnderOs::UI::Animation::Animation
- Inherits:
-
Object
- Object
- UnderOs::UI::Animation::Animation
- Defined in:
- lib/under_os/ui/utils/animation.rb
Constant Summary collapse
- CURVES =
{ ease_in_out: UIViewAnimationOptionCurveEaseInOut, ease_in: UIViewAnimationOptionCurveEaseIn, ease_out: UIViewAnimationOptionCurveEaseOut, linear: UIViewAnimationOptionCurveLinear }.freeze
- FX_QUEUE =
{}
Instance Method Summary collapse
- #delay ⇒ Object
- #duration ⇒ Object
-
#initialize(view, options, &block) ⇒ Animation
constructor
A new instance of Animation.
- #options ⇒ Object
- #queue ⇒ Object
- #run ⇒ Object
- #run_next ⇒ Object
- #schedule ⇒ Object
Constructor Details
#initialize(view, options, &block) ⇒ Animation
Returns a new instance of Animation.
45 46 47 48 49 50 51 52 53 |
# File 'lib/under_os/ui/utils/animation.rb', line 45 def initialize(view, , &block) @view = view @options = @block = block @options = {duration: } if .is_a?(Numeric) @options[:schedule] == false ? run : schedule end |
Instance Method Details
#delay ⇒ Object
81 82 83 |
# File 'lib/under_os/ui/utils/animation.rb', line 81 def delay @options[:delay] || 0.0 end |
#duration ⇒ Object
77 78 79 |
# File 'lib/under_os/ui/utils/animation.rb', line 77 def duration @options[:duration] || 0.25 end |
#options ⇒ Object
85 86 87 88 89 90 |
# File 'lib/under_os/ui/utils/animation.rb', line 85 def = CURVES[@options[:curve]] || @options[:curve] || UIViewAnimationCurveEaseOut = | UIViewAnimationOptionAutoreverse if @options[:autoreverse] = | UIViewAnimationOptionRepeat if @options[:repeat] | UIViewAnimationOptionAllowUserInteraction end |
#queue ⇒ Object
55 56 57 |
# File 'lib/under_os/ui/utils/animation.rb', line 55 def queue FX_QUEUE[@view] ||= [] end |
#run ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/under_os/ui/utils/animation.rb', line 67 def run @view.emit('animation:start') UIView.animateWithDuration duration, delay: delay, options: , animations: ->{ @block.call }, completion: ->(finished){ run_next } end |
#run_next ⇒ Object
92 93 94 95 96 97 98 99 |
# 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 ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/under_os/ui/utils/animation.rb', line 59 def schedule if queue.empty? run else queue << self end end |