default isInteraction to !useNativeDriver
Summary: [General] [Changed] - If `isInteraction` is not specified in the config, it would always default to `true` which would block interactions like VirtualizedList updates. This is generally not what you want with useNativeDriver since the animation won't be interrupted by JS. If something does end up interfering with an animation and causes frame drops, `isInteraction` can be set manually. Reviewed By: yungsters Differential Revision: D14988087 fbshipit-source-id: 791b5cc327ffef6d2720c647a228cf3134a27cda
This commit is contained in:
parent
184108f99b
commit
ded7119c9a
|
@ -38,13 +38,11 @@ class DecayAnimation extends Animation {
|
||||||
|
|
||||||
constructor(config: DecayAnimationConfigSingle) {
|
constructor(config: DecayAnimationConfigSingle) {
|
||||||
super();
|
super();
|
||||||
this._deceleration =
|
this._deceleration = config.deceleration ?? 0.998;
|
||||||
config.deceleration !== undefined ? config.deceleration : 0.998;
|
|
||||||
this._velocity = config.velocity;
|
this._velocity = config.velocity;
|
||||||
this._useNativeDriver = shouldUseNativeDriver(config);
|
this._useNativeDriver = shouldUseNativeDriver(config);
|
||||||
this.__isInteraction =
|
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
|
||||||
config.isInteraction !== undefined ? config.isInteraction : true;
|
this.__iterations = config.iterations ?? 1;
|
||||||
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__getNativeAnimationConfig() {
|
__getNativeAnimationConfig() {
|
||||||
|
|
|
@ -51,13 +51,6 @@ export type SpringAnimationConfigSingle = AnimationConfig & {
|
||||||
delay?: number,
|
delay?: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
function withDefault<T>(value: ?T, defaultValue: T): T {
|
|
||||||
if (value === undefined || value === null) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpringAnimation extends Animation {
|
class SpringAnimation extends Animation {
|
||||||
_overshootClamping: boolean;
|
_overshootClamping: boolean;
|
||||||
_restDisplacementThreshold: number;
|
_restDisplacementThreshold: number;
|
||||||
|
@ -83,20 +76,16 @@ class SpringAnimation extends Animation {
|
||||||
constructor(config: SpringAnimationConfigSingle) {
|
constructor(config: SpringAnimationConfigSingle) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._overshootClamping = withDefault(config.overshootClamping, false);
|
this._overshootClamping = config.overshootClamping ?? false;
|
||||||
this._restDisplacementThreshold = withDefault(
|
this._restDisplacementThreshold = config.restDisplacementThreshold ?? 0.001;
|
||||||
config.restDisplacementThreshold,
|
this._restSpeedThreshold = config.restSpeedThreshold ?? 0.001;
|
||||||
0.001,
|
this._initialVelocity = config.velocity ?? 0;
|
||||||
);
|
this._lastVelocity = config.velocity ?? 0;
|
||||||
this._restSpeedThreshold = withDefault(config.restSpeedThreshold, 0.001);
|
|
||||||
this._initialVelocity = withDefault(config.velocity, 0);
|
|
||||||
this._lastVelocity = withDefault(config.velocity, 0);
|
|
||||||
this._toValue = config.toValue;
|
this._toValue = config.toValue;
|
||||||
this._delay = withDefault(config.delay, 0);
|
this._delay = config.delay ?? 0;
|
||||||
this._useNativeDriver = shouldUseNativeDriver(config);
|
this._useNativeDriver = shouldUseNativeDriver(config);
|
||||||
this.__isInteraction =
|
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
|
||||||
config.isInteraction !== undefined ? config.isInteraction : true;
|
this.__iterations = config.iterations ?? 1;
|
||||||
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
config.stiffness !== undefined ||
|
config.stiffness !== undefined ||
|
||||||
|
@ -110,9 +99,9 @@ class SpringAnimation extends Animation {
|
||||||
config.friction === undefined,
|
config.friction === undefined,
|
||||||
'You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one',
|
'You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one',
|
||||||
);
|
);
|
||||||
this._stiffness = withDefault(config.stiffness, 100);
|
this._stiffness = config.stiffness ?? 100;
|
||||||
this._damping = withDefault(config.damping, 10);
|
this._damping = config.damping ?? 10;
|
||||||
this._mass = withDefault(config.mass, 1);
|
this._mass = config.mass ?? 1;
|
||||||
} else if (config.bounciness !== undefined || config.speed !== undefined) {
|
} else if (config.bounciness !== undefined || config.speed !== undefined) {
|
||||||
// Convert the origami bounciness/speed values to stiffness/damping
|
// Convert the origami bounciness/speed values to stiffness/damping
|
||||||
// We assume mass is 1.
|
// We assume mass is 1.
|
||||||
|
@ -125,8 +114,8 @@ class SpringAnimation extends Animation {
|
||||||
'You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one',
|
'You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one',
|
||||||
);
|
);
|
||||||
const springConfig = SpringConfig.fromBouncinessAndSpeed(
|
const springConfig = SpringConfig.fromBouncinessAndSpeed(
|
||||||
withDefault(config.bounciness, 8),
|
config.bounciness ?? 8,
|
||||||
withDefault(config.speed, 12),
|
config.speed ?? 12,
|
||||||
);
|
);
|
||||||
this._stiffness = springConfig.stiffness;
|
this._stiffness = springConfig.stiffness;
|
||||||
this._damping = springConfig.damping;
|
this._damping = springConfig.damping;
|
||||||
|
@ -135,8 +124,8 @@ class SpringAnimation extends Animation {
|
||||||
// Convert the origami tension/friction values to stiffness/damping
|
// Convert the origami tension/friction values to stiffness/damping
|
||||||
// We assume mass is 1.
|
// We assume mass is 1.
|
||||||
const springConfig = SpringConfig.fromOrigamiTensionAndFriction(
|
const springConfig = SpringConfig.fromOrigamiTensionAndFriction(
|
||||||
withDefault(config.tension, 40),
|
config.tension ?? 40,
|
||||||
withDefault(config.friction, 7),
|
config.friction ?? 7,
|
||||||
);
|
);
|
||||||
this._stiffness = springConfig.stiffness;
|
this._stiffness = springConfig.stiffness;
|
||||||
this._damping = springConfig.damping;
|
this._damping = springConfig.damping;
|
||||||
|
@ -157,7 +146,7 @@ class SpringAnimation extends Animation {
|
||||||
stiffness: this._stiffness,
|
stiffness: this._stiffness,
|
||||||
damping: this._damping,
|
damping: this._damping,
|
||||||
mass: this._mass,
|
mass: this._mass,
|
||||||
initialVelocity: withDefault(this._initialVelocity, this._lastVelocity),
|
initialVelocity: this._initialVelocity ?? this._lastVelocity,
|
||||||
toValue: this._toValue,
|
toValue: this._toValue,
|
||||||
iterations: this.__iterations,
|
iterations: this.__iterations,
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,13 +55,12 @@ class TimingAnimation extends Animation {
|
||||||
constructor(config: TimingAnimationConfigSingle) {
|
constructor(config: TimingAnimationConfigSingle) {
|
||||||
super();
|
super();
|
||||||
this._toValue = config.toValue;
|
this._toValue = config.toValue;
|
||||||
this._easing = config.easing !== undefined ? config.easing : easeInOut();
|
this._easing = config.easing ?? easeInOut();
|
||||||
this._duration = config.duration !== undefined ? config.duration : 500;
|
this._duration = config.duration ?? 500;
|
||||||
this._delay = config.delay !== undefined ? config.delay : 0;
|
this._delay = config.delay ?? 0;
|
||||||
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
|
this.__iterations = config.iterations ?? 1;
|
||||||
this.__isInteraction =
|
|
||||||
config.isInteraction !== undefined ? config.isInteraction : true;
|
|
||||||
this._useNativeDriver = shouldUseNativeDriver(config);
|
this._useNativeDriver = shouldUseNativeDriver(config);
|
||||||
|
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
__getNativeAnimationConfig(): any {
|
__getNativeAnimationConfig(): any {
|
||||||
|
|
Loading…
Reference in New Issue