Skip to content

Commit

Permalink
Animated: Rename __debouncedOnEnd to __notifyAnimationEnd
Browse files Browse the repository at this point in the history
Summary:
Simple rename of a protected method that should not be called by anyone outside of the `Animation` class and its subclasses, just to make it more intuitive.

Changelog:
[Internal]

Differential Revision: D63572363
  • Loading branch information
yungsters authored and facebook-github-bot committed Sep 28, 2024
1 parent 88498f8 commit e44d47f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
21 changes: 13 additions & 8 deletions packages/react-native/Libraries/Animated/animations/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ export default class Animation {
throw new Error('This animation type cannot be offloaded to native');
}

// Helper function for subclasses to make sure onEnd is only called once.
__debouncedOnEnd(result: EndResult): void {
const onEnd = this.#onEnd;
this.#onEnd = null;
onEnd && onEnd(result);
}

__findAnimatedPropsNodes(node: AnimatedNode): Array<AnimatedProps> {
const result = [];

Expand Down Expand Up @@ -129,7 +122,7 @@ export default class Animation {
animatedValue.__getNativeTag(),
config,
result => {
this.__debouncedOnEnd(result);
this.__notifyAnimationEnd(result);

// When using natively driven animations, once the animation completes,
// we need to ensure that the JS side nodes are synced with the updated
Expand Down Expand Up @@ -163,4 +156,16 @@ export default class Animation {
);
}
}

/**
* Notify the completion callback that the animation has ended. The completion
* callback will never be called more than once.
*/
__notifyAnimationEnd(result: EndResult): void {
const callback = this.#onEnd;
if (callback != null) {
this.#onEnd = null;
callback(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class DecayAnimation extends Animation {
this._onUpdate(value);

if (Math.abs(this._lastValue - value) < 0.1) {
this.__debouncedOnEnd({finished: true});
this.__notifyAnimationEnd({finished: true});
return;
}

Expand All @@ -116,6 +116,6 @@ export default class DecayAnimation extends Animation {
if (this._animationFrame != null) {
global.cancelAnimationFrame(this._animationFrame);
}
this.__debouncedOnEnd({finished: false});
this.__notifyAnimationEnd({finished: false});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export default class SpringAnimation extends Animation {
this._onUpdate(this._toValue);
}

this.__debouncedOnEnd({finished: true});
this.__notifyAnimationEnd({finished: true});
return;
}
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
Expand All @@ -367,6 +367,6 @@ export default class SpringAnimation extends Animation {
if (this._animationFrame != null) {
global.cancelAnimationFrame(this._animationFrame);
}
this.__debouncedOnEnd({finished: false});
this.__notifyAnimationEnd({finished: false});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class TimingAnimation extends Animation {
// not cause intermixed JS and native animations.
if (this._duration === 0) {
this._onUpdate(this._toValue);
this.__debouncedOnEnd({finished: true});
this.__notifyAnimationEnd({finished: true});
} else {
this._animationFrame = requestAnimationFrame(() => this.onUpdate());
}
Expand All @@ -147,7 +147,7 @@ export default class TimingAnimation extends Animation {
this._fromValue + this._easing(1) * (this._toValue - this._fromValue),
);
}
this.__debouncedOnEnd({finished: true});
this.__notifyAnimationEnd({finished: true});
return;
}

Expand All @@ -168,6 +168,6 @@ export default class TimingAnimation extends Animation {
if (this._animationFrame != null) {
global.cancelAnimationFrame(this._animationFrame);
}
this.__debouncedOnEnd({finished: false});
this.__notifyAnimationEnd({finished: false});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ declare export default class Animation {
platformConfig: ?PlatformConfig,
...
}>;
__debouncedOnEnd(result: EndResult): void;
__findAnimatedPropsNodes(node: AnimatedNode): Array<AnimatedProps>;
__startNativeAnimation(animatedValue: AnimatedValue): boolean;
__notifyAnimationEnd(result: EndResult): void;
}
"
`;
Expand Down

0 comments on commit e44d47f

Please sign in to comment.