( animations: Array<CompositeAnimation>, config?: ?ParallelConfig, )
| 198 | stopTogether?: bool; // If one is stopped, stop all. default: true |
| 199 | } |
| 200 | var parallel = function( |
| 201 | animations: Array<CompositeAnimation>, |
| 202 | config?: ?ParallelConfig, |
| 203 | ): CompositeAnimation { |
| 204 | var doneCount = 0; |
| 205 | // Make sure we only call stop() at most once for each animation |
| 206 | var hasEnded = {}; |
| 207 | var stopTogether = !(config && config.stopTogether === false); |
| 208 | |
| 209 | var result = { |
| 210 | start: function(callback?: ?EndCallback) { |
| 211 | if (doneCount === animations.length) { |
| 212 | callback && callback({finished: true}); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | animations.forEach((animation, idx) => { |
| 217 | var cb = function(endResult) { |
| 218 | hasEnded[idx] = true; |
| 219 | doneCount++; |
| 220 | if (doneCount === animations.length) { |
| 221 | doneCount = 0; |
| 222 | callback && callback(endResult); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | if (!endResult.finished && stopTogether) { |
| 227 | result.stop(); |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | if (!animation) { |
| 232 | cb({finished: true}); |
| 233 | } else { |
| 234 | animation.start(cb); |
| 235 | } |
| 236 | }); |
| 237 | }, |
| 238 | |
| 239 | stop: function(): void { |
| 240 | animations.forEach((animation, idx) => { |
| 241 | !hasEnded[idx] && animation.stop(); |
| 242 | hasEnded[idx] = true; |
| 243 | }); |
| 244 | } |
| 245 | }; |
| 246 | |
| 247 | return result; |
| 248 | }; |
| 249 | |
| 250 | var delay = function(time: number): CompositeAnimation { |
| 251 | // Would be nice to make a specialized implementation |
no test coverage detected
searching dependent graphs…