Animated: Simplify TimingAnimation#start Logic (#46719)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46719

Implements a minor refactor of `TimingAnimation#start` so that we standardize how the `_useNativeDriver` case is handled.

There is no behavior change from this besides more consistently assigning to `this._startTime`. (Previously, we would not set it if the duration were 0 and `!useNativeDriver`.)

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D63572066

fbshipit-source-id: 9cbd05c5ca5e00227be69441b9d7d8a502690246
This commit is contained in:
Tim Yung
2024-10-02 02:07:00 -07:00
committed by Facebook GitHub Bot
parent 85aa9278f9
commit 63100a9639
@@ -113,25 +113,26 @@ export default class TimingAnimation extends Animation {
this._fromValue = fromValue;
this._onUpdate = onUpdate;
const start = () => {
if (!this._useNativeDriver && animatedValue.__isNative === true) {
throw new Error(
'Attempting to run JS driven animation on animated node ' +
'that has been moved to "native" earlier by starting an ' +
'animation with `useNativeDriver: true`',
);
}
if (!this._useNativeDriver && animatedValue.__isNative === true) {
throw new Error(
'Attempting to run JS driven animation on animated node ' +
'that has been moved to "native" earlier by starting an ' +
'animation with `useNativeDriver: true`',
);
}
// Animations that sometimes have 0 duration and sometimes do not
// still need to use the native driver when duration is 0 so as to
// not cause intermixed JS and native animations.
if (this._duration === 0 && !this._useNativeDriver) {
this._onUpdate(this._toValue);
this.__debouncedOnEnd({finished: true});
const start = () => {
this._startTime = Date.now();
if (this._useNativeDriver) {
this.__startNativeAnimation(animatedValue);
} else {
this._startTime = Date.now();
if (this._useNativeDriver) {
this.__startNativeAnimation(animatedValue);
// Animations that sometimes have 0 duration and sometimes do not
// still need to use the native driver when duration is 0 so as to
// not cause intermixed JS and native animations.
if (this._duration === 0) {
this._onUpdate(this._toValue);
this.__debouncedOnEnd({finished: true});
} else {
this._animationFrame = requestAnimationFrame(
// $FlowFixMe[method-unbinding] added when improving typing for this parameters