| 158 | }; |
| 159 | |
| 160 | var sequence = function( |
| 161 | animations: Array<CompositeAnimation>, |
| 162 | ): CompositeAnimation { |
| 163 | var current = 0; |
| 164 | return { |
| 165 | start: function(callback?: ?EndCallback) { |
| 166 | var onComplete = function(result) { |
| 167 | if (!result.finished) { |
| 168 | callback && callback(result); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | current++; |
| 173 | |
| 174 | if (current === animations.length) { |
| 175 | callback && callback(result); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | animations[current].start(onComplete); |
| 180 | }; |
| 181 | |
| 182 | if (animations.length === 0) { |
| 183 | callback && callback({finished: true}); |
| 184 | } else { |
| 185 | animations[current].start(onComplete); |
| 186 | } |
| 187 | }, |
| 188 | |
| 189 | stop: function() { |
| 190 | if (current < animations.length) { |
| 191 | animations[current].stop(); |
| 192 | } |
| 193 | } |
| 194 | }; |
| 195 | }; |
| 196 | |
| 197 | type ParallelConfig = { |
| 198 | stopTogether?: bool; // If one is stopped, stop all. default: true |