Skip to content

Commit

Permalink
default isInteraction to !useNativeDriver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sahrens authored and facebook-github-bot committed Apr 27, 2019
1 parent 30348f7 commit 8f186b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
8 changes: 3 additions & 5 deletions Libraries/Animated/src/animations/DecayAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ class DecayAnimation extends Animation {

constructor(config: DecayAnimationConfigSingle) {
super();
this._deceleration =
config.deceleration !== undefined ? config.deceleration : 0.998;
this._deceleration = config.deceleration ?? 0.998;
this._velocity = config.velocity;
this._useNativeDriver = shouldUseNativeDriver(config);
this.__isInteraction =
config.isInteraction !== undefined ? config.isInteraction : true;
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
this.__iterations = config.iterations ?? 1;
}

__getNativeAnimationConfig() {
Expand Down
43 changes: 16 additions & 27 deletions Libraries/Animated/src/animations/SpringAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export type SpringAnimationConfigSingle = AnimationConfig & {
delay?: number,
};

function withDefault<T>(value: ?T, defaultValue: T): T {
if (value === undefined || value === null) {
return defaultValue;
}
return value;
}

class SpringAnimation extends Animation {
_overshootClamping: boolean;
_restDisplacementThreshold: number;
Expand All @@ -83,20 +76,16 @@ class SpringAnimation extends Animation {
constructor(config: SpringAnimationConfigSingle) {
super();

this._overshootClamping = withDefault(config.overshootClamping, false);
this._restDisplacementThreshold = withDefault(
config.restDisplacementThreshold,
0.001,
);
this._restSpeedThreshold = withDefault(config.restSpeedThreshold, 0.001);
this._initialVelocity = withDefault(config.velocity, 0);
this._lastVelocity = withDefault(config.velocity, 0);
this._overshootClamping = config.overshootClamping ?? false;
this._restDisplacementThreshold = config.restDisplacementThreshold ?? 0.001;
this._restSpeedThreshold = config.restSpeedThreshold ?? 0.001;
this._initialVelocity = config.velocity ?? 0;
this._lastVelocity = config.velocity ?? 0;
this._toValue = config.toValue;
this._delay = withDefault(config.delay, 0);
this._delay = config.delay ?? 0;
this._useNativeDriver = shouldUseNativeDriver(config);
this.__isInteraction =
config.isInteraction !== undefined ? config.isInteraction : true;
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
this.__iterations = config.iterations ?? 1;

if (
config.stiffness !== undefined ||
Expand All @@ -110,9 +99,9 @@ class SpringAnimation extends Animation {
config.friction === undefined,
'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._damping = withDefault(config.damping, 10);
this._mass = withDefault(config.mass, 1);
this._stiffness = config.stiffness ?? 100;
this._damping = config.damping ?? 10;
this._mass = config.mass ?? 1;
} else if (config.bounciness !== undefined || config.speed !== undefined) {
// Convert the origami bounciness/speed values to stiffness/damping
// We assume mass is 1.
Expand All @@ -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',
);
const springConfig = SpringConfig.fromBouncinessAndSpeed(
withDefault(config.bounciness, 8),
withDefault(config.speed, 12),
config.bounciness ?? 8,
config.speed ?? 12,
);
this._stiffness = springConfig.stiffness;
this._damping = springConfig.damping;
Expand All @@ -135,8 +124,8 @@ class SpringAnimation extends Animation {
// Convert the origami tension/friction values to stiffness/damping
// We assume mass is 1.
const springConfig = SpringConfig.fromOrigamiTensionAndFriction(
withDefault(config.tension, 40),
withDefault(config.friction, 7),
config.tension ?? 40,
config.friction ?? 7,
);
this._stiffness = springConfig.stiffness;
this._damping = springConfig.damping;
Expand All @@ -157,7 +146,7 @@ class SpringAnimation extends Animation {
stiffness: this._stiffness,
damping: this._damping,
mass: this._mass,
initialVelocity: withDefault(this._initialVelocity, this._lastVelocity),
initialVelocity: this._initialVelocity ?? this._lastVelocity,
toValue: this._toValue,
iterations: this.__iterations,
};
Expand Down
11 changes: 5 additions & 6 deletions Libraries/Animated/src/animations/TimingAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ class TimingAnimation extends Animation {
constructor(config: TimingAnimationConfigSingle) {
super();
this._toValue = config.toValue;
this._easing = config.easing !== undefined ? config.easing : easeInOut();
this._duration = config.duration !== undefined ? config.duration : 500;
this._delay = config.delay !== undefined ? config.delay : 0;
this.__iterations = config.iterations !== undefined ? config.iterations : 1;
this.__isInteraction =
config.isInteraction !== undefined ? config.isInteraction : true;
this._easing = config.easing ?? easeInOut();
this._duration = config.duration ?? 500;
this._delay = config.delay ?? 0;
this.__iterations = config.iterations ?? 1;
this._useNativeDriver = shouldUseNativeDriver(config);
this.__isInteraction = config.isInteraction ?? !this._useNativeDriver;
}

__getNativeAnimationConfig(): any {
Expand Down

0 comments on commit 8f186b8

Please sign in to comment.