MCPcopy Create free account
hub / github.com/ptmt/react-native-macos / loop

Function loop

Libraries/Animated/src/AnimatedImplementation.js:2293–2342  ·  view source on GitHub ↗
(
  animation: CompositeAnimation,
  { iterations = -1 }: LoopAnimationConfig = {},
)

Source from the content-addressed store, hash-verified

2291type LoopAnimationConfig = { iterations: number };
2292
2293var loop = function(
2294 animation: CompositeAnimation,
2295 { iterations = -1 }: LoopAnimationConfig = {},
2296): CompositeAnimation {
2297 var isFinished = false;
2298 var iterationsSoFar = 0;
2299 return {
2300 start: function(callback?: ?EndCallback) {
2301 var restart = function(result: EndResult = {finished: true}): void {
2302 if (isFinished ||
2303 (iterationsSoFar === iterations) ||
2304 (result.finished === false)) {
2305 callback && callback(result);
2306 } else {
2307 iterationsSoFar++;
2308 animation.reset();
2309 animation.start(restart);
2310 }
2311 };
2312 if (!animation || iterations === 0) {
2313 callback && callback({finished: true});
2314 } else {
2315 if (animation._isUsingNativeDriver()) {
2316 animation._startNativeLoop(iterations);
2317 } else {
2318 restart(); // Start looping recursively on the js thread
2319 }
2320 }
2321 },
2322
2323 stop: function(): void {
2324 isFinished = true;
2325 animation.stop();
2326 },
2327
2328 reset: function(): void {
2329 iterationsSoFar = 0;
2330 isFinished = false;
2331 animation.reset();
2332 },
2333
2334 _startNativeLoop: function() {
2335 throw new Error('Loops run using the native driver cannot contain Animated.loop animations');
2336 },
2337
2338 _isUsingNativeDriver: function(): boolean {
2339 return animation._isUsingNativeDriver();
2340 }
2341 };
2342};
2343
2344type Mapping = {[key: string]: Mapping} | AnimatedValue;
2345type EventConfig = {

Callers

nothing calls this directly

Calls 4

restartFunction · 0.85
callbackFunction · 0.50
stopMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…