Class: Dommy::Animation
Overview
Animation — represents a running animation, mirroring the Web
Animations API's lifecycle and event surface. Dommy doesn't
interpolate any property values; the animation transitions
through "idle" → "running" → "finished" by either virtual time
(scheduler.advance_time) or by an explicit finish() call.
Spec: https://drafts.csswg.org/web-animations/#animation
Instance Attribute Summary collapse
Instance Method Summary
collapse
included
#__dommy_dump_event_failure__, #__internal_deliver_event__, #__internal_process_event_handler_return__, #add_event_listener, capture_flag, #deliver_at, #dispatch_event, #event_name_from_on, #invoke_listener_isolated, js_truthy?, #on_handler, #remove_event_listener, #set_on_handler
Constructor Details
#initialize(effect = nil, timeline = nil, window: nil) ⇒ Animation
Returns a new instance of Animation.
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/dommy/animation.rb', line 95
def initialize(effect = nil, timeline = nil, window: nil)
@effect = effect
@timeline = timeline
@window = window
@play_state = "idle"
@playback_rate = 1.0
@current_time = nil
@start_time = nil
@id = ""
@finished_promise = nil
@ready_promise = nil
@scheduled_finish_id = nil
end
|
Instance Attribute Details
#effect ⇒ Object
Returns the value of attribute effect.
93
94
95
|
# File 'lib/dommy/animation.rb', line 93
def effect
@effect
end
|
#id ⇒ Object
Returns the value of attribute id.
92
93
94
|
# File 'lib/dommy/animation.rb', line 92
def id
@id
end
|
#play_state ⇒ Object
Returns the value of attribute play_state.
93
94
95
|
# File 'lib/dommy/animation.rb', line 93
def play_state
@play_state
end
|
#timeline ⇒ Object
Returns the value of attribute timeline.
93
94
95
|
# File 'lib/dommy/animation.rb', line 93
def timeline
@timeline
end
|
Instance Method Details
#__internal_event_parent__ ⇒ Object
Event bubbling stops at Animation — it isn't part of the DOM tree.
259
260
261
|
# File 'lib/dommy/animation.rb', line 259
def __internal_event_parent__
nil
end
|
#__js_call__(method, args) ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/dommy/animation.rb', line 237
def __js_call__(method, args)
case method
when "play"
play
when "pause"
pause
when "cancel"
cancel
when "finish"
finish
when "reverse"
reverse
when "addEventListener"
add_event_listener(args[0], args[1], args[2])
when "removeEventListener"
remove_event_listener(args[0], args[1], args[2])
when "dispatchEvent"
dispatch_event(args[0])
end
end
|
#__js_get__(key) ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/dommy/animation.rb', line 191
def __js_get__(key)
case key
when "playState"
@play_state
when "playbackRate"
@playback_rate
when "currentTime"
@current_time
when "startTime"
@start_time
when "effect"
@effect
when "timeline"
@timeline
when "finished"
finished
when "ready"
ready
when "id"
@id
else
Bridge::ABSENT
end
end
|
#__js_set__(key, value) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/dommy/animation.rb', line 216
def __js_set__(key, value)
case key
when "currentTime"
@current_time = value
when "startTime"
@start_time = value
when "playbackRate"
@playback_rate = value.to_f
when "id"
@id = value.to_s
else
return Bridge::UNHANDLED
end
nil
end
|
#cancel ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/dommy/animation.rb', line 151
def cancel
cancel_scheduled_finish
@play_state = "idle"
@current_time = nil
reject_finished_with_abort
dispatch_event(Event.new("cancel"))
self
end
|
#current_time ⇒ Object
109
110
111
|
# File 'lib/dommy/animation.rb', line 109
def current_time
@current_time
end
|
#current_time=(value) ⇒ Object
113
114
115
|
# File 'lib/dommy/animation.rb', line 113
def current_time=(value)
@current_time = value
end
|
#finish ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/dommy/animation.rb', line 160
def finish
cancel_scheduled_finish
@play_state = "finished"
@current_time = effect_duration_ms
resolve_finished
dispatch_event(Event.new("finish"))
self
end
|
#finished ⇒ Object
PromiseValue that resolves when the animation finishes.
Rejected (with AbortError-style RuntimeError) on cancel.
177
178
179
|
# File 'lib/dommy/animation.rb', line 177
def finished
@finished_promise ||= PromiseValue.new(@window)
end
|
#pause ⇒ Object
145
146
147
148
149
|
# File 'lib/dommy/animation.rb', line 145
def pause
cancel_scheduled_finish
@play_state = "paused" unless @play_state == "idle"
self
end
|
#play ⇒ Object
Start (or resume) the animation. Returns self.
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/dommy/animation.rb', line 134
def play
return self if @play_state == "running"
previous = @play_state
@play_state = "running"
@start_time ||= @window&.scheduler&.now_ms || 0
ensure_ready_resolved
schedule_auto_finish if previous != "paused"
self
end
|
#playback_rate ⇒ Object
125
126
127
|
# File 'lib/dommy/animation.rb', line 125
def playback_rate
@playback_rate
end
|
#playback_rate=(value) ⇒ Object
129
130
131
|
# File 'lib/dommy/animation.rb', line 129
def playback_rate=(value)
@playback_rate = value.to_f
end
|
#ready ⇒ Object
PromiseValue that resolves once the animation is ready to play
(immediately in Dommy — there's no render-thread handoff).
183
184
185
186
187
188
189
|
# File 'lib/dommy/animation.rb', line 183
def ready
@ready_promise ||= if @window
PromiseValue.resolve(@window, self)
else
PromiseValue.new(@window)
end
end
|
#reverse ⇒ Object
169
170
171
172
173
|
# File 'lib/dommy/animation.rb', line 169
def reverse
@playback_rate = -@playback_rate
play if @play_state == "idle"
self
end
|
#start_time ⇒ Object
117
118
119
|
# File 'lib/dommy/animation.rb', line 117
def start_time
@start_time
end
|
#start_time=(value) ⇒ Object
121
122
123
|
# File 'lib/dommy/animation.rb', line 121
def start_time=(value)
@start_time = value
end
|