mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Prettier React Native Libraries
Reviewed By: sahrens Differential Revision: D7961488 fbshipit-source-id: 05f9b8b0b91ae77f9040a5321ccc18f7c3c1ce9a
This commit is contained in:
committed by
Facebook Github Bot
parent
1e2de71290
commit
d01ab66b47
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -20,58 +22,52 @@ var objectAssign = require('object-assign');
|
||||
var runSequence = require('run-sequence');
|
||||
var webpackStream = require('webpack-stream');
|
||||
|
||||
var DEVELOPMENT_HEADER = [
|
||||
'/**',
|
||||
' * Animated v<%= version %>',
|
||||
' */'
|
||||
].join('\n') + '\n';
|
||||
var PRODUCTION_HEADER = [
|
||||
'/**',
|
||||
' * Animated v<%= version %>',
|
||||
' *',
|
||||
' * Copyright (c) 2013-present, Facebook, Inc.',
|
||||
' *',
|
||||
' * This source code is licensed under the MIT license found in the',
|
||||
' * LICENSE file in the root directory of this source tree.',
|
||||
' */'
|
||||
].join('\n') + '\n';
|
||||
var DEVELOPMENT_HEADER =
|
||||
['/**', ' * Animated v<%= version %>', ' */'].join('\n') + '\n';
|
||||
var PRODUCTION_HEADER =
|
||||
[
|
||||
'/**',
|
||||
' * Animated v<%= version %>',
|
||||
' *',
|
||||
' * Copyright (c) 2013-present, Facebook, Inc.',
|
||||
' *',
|
||||
' * This source code is licensed under the MIT license found in the',
|
||||
' * LICENSE file in the root directory of this source tree.',
|
||||
' */',
|
||||
].join('\n') + '\n';
|
||||
|
||||
var babelOpts = {
|
||||
nonStandard: true,
|
||||
loose: [
|
||||
'es6.classes'
|
||||
],
|
||||
loose: ['es6.classes'],
|
||||
stage: 1,
|
||||
plugins: [babelPluginDEV, babelPluginModules],
|
||||
_moduleMap: objectAssign({}, require('fbjs/module-map'), {
|
||||
'React': 'react',
|
||||
})
|
||||
React: 'react',
|
||||
}),
|
||||
};
|
||||
|
||||
var buildDist = function(opts) {
|
||||
var webpackOpts = {
|
||||
debug: opts.debug,
|
||||
externals: {
|
||||
'react': 'React',
|
||||
react: 'React',
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{test: /\.js$/, loader: 'babel'}
|
||||
],
|
||||
loaders: [{test: /\.js$/, loader: 'babel'}],
|
||||
},
|
||||
output: {
|
||||
filename: opts.output,
|
||||
library: 'Animated'
|
||||
library: 'Animated',
|
||||
},
|
||||
plugins: [
|
||||
new webpackStream.webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(
|
||||
opts.debug ? 'development' : 'production'
|
||||
opts.debug ? 'development' : 'production',
|
||||
),
|
||||
}),
|
||||
new webpackStream.webpack.optimize.OccurenceOrderPlugin(),
|
||||
new webpackStream.webpack.optimize.DedupePlugin()
|
||||
]
|
||||
new webpackStream.webpack.optimize.DedupePlugin(),
|
||||
],
|
||||
};
|
||||
if (!opts.debug) {
|
||||
webpackOpts.plugins.push(
|
||||
@@ -79,9 +75,9 @@ var buildDist = function(opts) {
|
||||
compress: {
|
||||
hoist_vars: true,
|
||||
screw_ie8: true,
|
||||
warnings: false
|
||||
}
|
||||
})
|
||||
warnings: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
return webpackStream(webpackOpts, null, function(err, stats) {
|
||||
@@ -101,7 +97,7 @@ var paths = {
|
||||
src: [
|
||||
'*src/**/*.js',
|
||||
'!src/**/__tests__/**/*.js',
|
||||
'!src/**/__mocks__/**/*.js'
|
||||
'!src/**/__mocks__/**/*.js',
|
||||
],
|
||||
};
|
||||
|
||||
@@ -117,32 +113,36 @@ gulp.task('modules', function() {
|
||||
.pipe(gulp.dest(paths.lib));
|
||||
});
|
||||
|
||||
gulp.task('dist', ['modules'], function () {
|
||||
gulp.task('dist', ['modules'], function() {
|
||||
var distOpts = {
|
||||
debug: true,
|
||||
output: 'animated.js'
|
||||
output: 'animated.js',
|
||||
};
|
||||
return gulp
|
||||
.src(paths.entry)
|
||||
.pipe(buildDist(distOpts))
|
||||
.pipe(derequire())
|
||||
.pipe(header(DEVELOPMENT_HEADER, {
|
||||
version: process.env.npm_package_version
|
||||
}))
|
||||
.pipe(
|
||||
header(DEVELOPMENT_HEADER, {
|
||||
version: process.env.npm_package_version,
|
||||
}),
|
||||
)
|
||||
.pipe(gulp.dest(paths.dist));
|
||||
});
|
||||
|
||||
gulp.task('dist:min', ['modules'], function () {
|
||||
gulp.task('dist:min', ['modules'], function() {
|
||||
var distOpts = {
|
||||
debug: false,
|
||||
output: 'animated.min.js'
|
||||
output: 'animated.min.js',
|
||||
};
|
||||
return gulp
|
||||
.src(paths.entry)
|
||||
.pipe(buildDist(distOpts))
|
||||
.pipe(header(PRODUCTION_HEADER, {
|
||||
version: process.env.npm_package_version
|
||||
}))
|
||||
.pipe(
|
||||
header(PRODUCTION_HEADER, {
|
||||
version: process.env.npm_package_version,
|
||||
}),
|
||||
)
|
||||
.pipe(gulp.dest(paths.dist));
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const AnimatedImplementation = require('AnimatedImplementation');
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let ease;
|
||||
@@ -162,7 +164,7 @@ class Easing {
|
||||
*/
|
||||
static elastic(bounciness: number = 1): (t: number) => number {
|
||||
const p = bounciness * Math.PI;
|
||||
return (t) => 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p);
|
||||
return t => 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +179,7 @@ class Easing {
|
||||
if (s === undefined) {
|
||||
s = 1.70158;
|
||||
}
|
||||
return (t) => t * t * ((s + 1) * t - s);
|
||||
return t => t * t * ((s + 1) * t - s);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,7 +217,7 @@ class Easing {
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number
|
||||
y2: number,
|
||||
): (t: number) => number {
|
||||
const _bezier = require('bezier');
|
||||
return _bezier(x1, y1, x2, y2);
|
||||
@@ -224,19 +226,15 @@ class Easing {
|
||||
/**
|
||||
* Runs an easing function forwards.
|
||||
*/
|
||||
static in(
|
||||
easing: (t: number) => number,
|
||||
): (t: number) => number {
|
||||
static in(easing: (t: number) => number): (t: number) => number {
|
||||
return easing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an easing function backwards.
|
||||
*/
|
||||
static out(
|
||||
easing: (t: number) => number,
|
||||
): (t: number) => number {
|
||||
return (t) => 1 - easing(1 - t);
|
||||
static out(easing: (t: number) => number): (t: number) => number {
|
||||
return t => 1 - easing(1 - t);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,10 +242,8 @@ class Easing {
|
||||
* forwards for half of the duration, then backwards for the rest of the
|
||||
* duration.
|
||||
*/
|
||||
static inOut(
|
||||
easing: (t: number) => number,
|
||||
): (t: number) => number {
|
||||
return (t) => {
|
||||
static inOut(easing: (t: number) => number): (t: number) => number {
|
||||
return t => {
|
||||
if (t < 0.5) {
|
||||
return easing(t * 2) / 2;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
@@ -41,7 +42,7 @@ function fromBouncinessAndSpeed(
|
||||
}
|
||||
|
||||
function projectNormal(n, start, end) {
|
||||
return start + (n * (end - start));
|
||||
return start + n * (end - start);
|
||||
}
|
||||
|
||||
function linearInterpolation(t, start, end) {
|
||||
@@ -53,18 +54,20 @@ function fromBouncinessAndSpeed(
|
||||
}
|
||||
|
||||
function b3Friction1(x) {
|
||||
return (0.0007 * Math.pow(x, 3)) -
|
||||
(0.031 * Math.pow(x, 2)) + 0.64 * x + 1.28;
|
||||
return 0.0007 * Math.pow(x, 3) - 0.031 * Math.pow(x, 2) + 0.64 * x + 1.28;
|
||||
}
|
||||
|
||||
function b3Friction2(x) {
|
||||
return (0.000044 * Math.pow(x, 3)) -
|
||||
(0.006 * Math.pow(x, 2)) + 0.36 * x + 2;
|
||||
return 0.000044 * Math.pow(x, 3) - 0.006 * Math.pow(x, 2) + 0.36 * x + 2;
|
||||
}
|
||||
|
||||
function b3Friction3(x) {
|
||||
return (0.00000045 * Math.pow(x, 3)) -
|
||||
(0.000332 * Math.pow(x, 2)) + 0.1078 * x + 5.84;
|
||||
return (
|
||||
0.00000045 * Math.pow(x, 3) -
|
||||
0.000332 * Math.pow(x, 2) +
|
||||
0.1078 * x +
|
||||
5.84
|
||||
);
|
||||
}
|
||||
|
||||
function b3Nobounce(tension) {
|
||||
@@ -84,7 +87,7 @@ function fromBouncinessAndSpeed(
|
||||
const bouncyFriction = quadraticOutInterpolation(
|
||||
b,
|
||||
b3Nobounce(bouncyTension),
|
||||
0.01
|
||||
0.01,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let Animated = require('Animated');
|
||||
@@ -15,29 +17,33 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
describe('Animated', () => {
|
||||
|
||||
it('works end to end', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
|
||||
const callback = jest.fn();
|
||||
|
||||
const node = new Animated.__PropsOnlyForTests({
|
||||
style: {
|
||||
backgroundColor: 'red',
|
||||
opacity: anim,
|
||||
transform: [
|
||||
{translateX: anim.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [100, 200],
|
||||
})},
|
||||
{scale: anim},
|
||||
],
|
||||
shadowOffset: {
|
||||
width: anim,
|
||||
height: anim,
|
||||
const node = new Animated.__PropsOnlyForTests(
|
||||
{
|
||||
style: {
|
||||
backgroundColor: 'red',
|
||||
opacity: anim,
|
||||
transform: [
|
||||
{
|
||||
translateX: anim.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [100, 200],
|
||||
}),
|
||||
},
|
||||
{scale: anim},
|
||||
],
|
||||
shadowOffset: {
|
||||
width: anim,
|
||||
height: anim,
|
||||
},
|
||||
},
|
||||
}
|
||||
}, callback);
|
||||
},
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(anim.__getChildren().length).toBe(3);
|
||||
|
||||
@@ -45,10 +51,7 @@ describe('Animated tests', () => {
|
||||
style: {
|
||||
backgroundColor: 'red',
|
||||
opacity: 0,
|
||||
transform: [
|
||||
{translateX: 100},
|
||||
{scale: 0},
|
||||
],
|
||||
transform: [{translateX: 100}, {scale: 0}],
|
||||
shadowOffset: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
@@ -64,10 +67,7 @@ describe('Animated tests', () => {
|
||||
style: {
|
||||
backgroundColor: 'red',
|
||||
opacity: 0.5,
|
||||
transform: [
|
||||
{translateX: 150},
|
||||
{scale: 0.5},
|
||||
],
|
||||
transform: [{translateX: 150}, {scale: 0.5}],
|
||||
shadowOffset: {
|
||||
width: 0.5,
|
||||
height: 0.5,
|
||||
@@ -107,7 +107,6 @@ describe('Animated tests', () => {
|
||||
expect(anim.__detach).toBeCalled();
|
||||
});
|
||||
|
||||
|
||||
it('stops animation when detached', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
const callback = jest.fn();
|
||||
@@ -141,7 +140,8 @@ describe('Animated tests', () => {
|
||||
anim.addListener(listener);
|
||||
Animated.spring(anim, {toValue: 15}).start();
|
||||
jest.runAllTimers();
|
||||
const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
const lastValue =
|
||||
listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
expect(lastValue).not.toBe(15);
|
||||
expect(lastValue).toBeCloseTo(15);
|
||||
expect(anim.__getValue()).toBe(15);
|
||||
@@ -151,9 +151,14 @@ describe('Animated tests', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
anim.addListener(listener);
|
||||
Animated.spring(anim, {stiffness: 8000, damping: 2000, toValue: 15}).start();
|
||||
Animated.spring(anim, {
|
||||
stiffness: 8000,
|
||||
damping: 2000,
|
||||
toValue: 15,
|
||||
}).start();
|
||||
jest.runAllTimers();
|
||||
const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
const lastValue =
|
||||
listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
expect(lastValue).not.toBe(15);
|
||||
expect(lastValue).toBeCloseTo(15);
|
||||
expect(anim.__getValue()).toBe(15);
|
||||
@@ -164,9 +169,7 @@ describe('Animated tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Animated Sequence', () => {
|
||||
|
||||
it('works with an empty sequence', () => {
|
||||
const cb = jest.fn();
|
||||
Animated.sequence([]).start(cb);
|
||||
@@ -232,9 +235,12 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
describe('Animated Loop', () => {
|
||||
|
||||
it('loops indefinitely if config not specified', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation);
|
||||
@@ -261,10 +267,14 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops indefinitely if iterations is -1', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, { iterations: -1 });
|
||||
const loop = Animated.loop(animation, {iterations: -1});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -288,10 +298,14 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops indefinitely if iterations not specified', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, { anotherKey: 'value' });
|
||||
const loop = Animated.loop(animation, {anotherKey: 'value'});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -315,10 +329,14 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops three times if iterations is 3', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, { iterations: 3 });
|
||||
const loop = Animated.loop(animation, {iterations: 3});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -342,10 +360,14 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not loop if iterations is 1', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, { iterations: 1 });
|
||||
const loop = Animated.loop(animation, {iterations: 1});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -359,10 +381,14 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not animate if iterations is 0', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, { iterations: 0 });
|
||||
const loop = Animated.loop(animation, {iterations: 0});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -373,7 +399,11 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports interrupting an indefinite loop', () => {
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
Animated.loop(animation).start(cb);
|
||||
@@ -391,7 +421,12 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports stopping loop', () => {
|
||||
const animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation);
|
||||
@@ -409,7 +444,6 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
describe('Animated Parallel', () => {
|
||||
|
||||
it('works with an empty parallel', () => {
|
||||
const cb = jest.fn();
|
||||
Animated.parallel([]).start(cb);
|
||||
@@ -470,7 +504,6 @@ describe('Animated tests', () => {
|
||||
expect(cb).toBeCalledWith({finished: false});
|
||||
});
|
||||
|
||||
|
||||
it('does not call stop more than once when stopping', () => {
|
||||
const anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
const anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
@@ -504,10 +537,7 @@ describe('Animated tests', () => {
|
||||
it('should call anim after delay in sequence', () => {
|
||||
const anim = {start: jest.fn(), stop: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
Animated.sequence([
|
||||
Animated.delay(1000),
|
||||
anim,
|
||||
]).start(cb);
|
||||
Animated.sequence([Animated.delay(1000), anim]).start(cb);
|
||||
jest.runAllTimers();
|
||||
expect(anim.start.mock.calls.length).toBe(1);
|
||||
expect(cb).not.toBeCalled();
|
||||
@@ -529,19 +559,14 @@ describe('Animated tests', () => {
|
||||
describe('Animated Events', () => {
|
||||
it('should map events', () => {
|
||||
const value = new Animated.Value(0);
|
||||
const handler = Animated.event(
|
||||
[null, {state: {foo: value}}],
|
||||
);
|
||||
const handler = Animated.event([null, {state: {foo: value}}]);
|
||||
handler({bar: 'ignoreBar'}, {state: {baz: 'ignoreBaz', foo: 42}});
|
||||
expect(value.__getValue()).toBe(42);
|
||||
});
|
||||
it('should call listeners', () => {
|
||||
const value = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const handler = Animated.event(
|
||||
[{foo: value}],
|
||||
{listener},
|
||||
);
|
||||
const handler = Animated.event([{foo: value}], {listener});
|
||||
handler({foo: 42});
|
||||
expect(value.__getValue()).toBe(42);
|
||||
expect(listener.mock.calls.length).toBe(1);
|
||||
@@ -550,10 +575,7 @@ describe('Animated tests', () => {
|
||||
it('should call forked event listeners', () => {
|
||||
const value = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const handler = Animated.event(
|
||||
[{foo: value}],
|
||||
{listener},
|
||||
);
|
||||
const handler = Animated.event([{foo: value}], {listener});
|
||||
const listener2 = jest.fn();
|
||||
const forkedHandler = Animated.forkEvent(handler, listener2);
|
||||
forkedHandler({foo: 42});
|
||||
@@ -577,7 +599,7 @@ describe('Animated tests', () => {
|
||||
InteractionManager = require('InteractionManager');
|
||||
});
|
||||
|
||||
afterEach(()=> {
|
||||
afterEach(() => {
|
||||
jest.unmock('InteractionManager');
|
||||
});
|
||||
|
||||
@@ -633,7 +655,7 @@ describe('Animated tests', () => {
|
||||
Animated.timing(value2, {
|
||||
toValue: value1.interpolate({
|
||||
inputRange: [0, 2],
|
||||
outputRange: [0, 1]
|
||||
outputRange: [0, 1],
|
||||
}),
|
||||
duration: 0,
|
||||
}).start();
|
||||
@@ -665,24 +687,24 @@ describe('Animated tests', () => {
|
||||
|
||||
const callback = jest.fn();
|
||||
|
||||
const node = new Animated.__PropsOnlyForTests({
|
||||
style: {
|
||||
opacity: vec.x.interpolate({
|
||||
inputRange: [0, 42],
|
||||
outputRange: [0.2, 0.8],
|
||||
}),
|
||||
transform: vec.getTranslateTransform(),
|
||||
...vec.getLayout(),
|
||||
}
|
||||
}, callback);
|
||||
const node = new Animated.__PropsOnlyForTests(
|
||||
{
|
||||
style: {
|
||||
opacity: vec.x.interpolate({
|
||||
inputRange: [0, 42],
|
||||
outputRange: [0.2, 0.8],
|
||||
}),
|
||||
transform: vec.getTranslateTransform(),
|
||||
...vec.getLayout(),
|
||||
},
|
||||
},
|
||||
callback,
|
||||
);
|
||||
|
||||
expect(node.__getValue()).toEqual({
|
||||
style: {
|
||||
opacity: 0.2,
|
||||
transform: [
|
||||
{translateX: 0},
|
||||
{translateY: 0},
|
||||
],
|
||||
transform: [{translateX: 0}, {translateY: 0}],
|
||||
left: 0,
|
||||
top: 0,
|
||||
},
|
||||
@@ -695,10 +717,7 @@ describe('Animated tests', () => {
|
||||
expect(node.__getValue()).toEqual({
|
||||
style: {
|
||||
opacity: 0.8,
|
||||
transform: [
|
||||
{translateX: 42},
|
||||
{translateY: 1492},
|
||||
],
|
||||
transform: [{translateX: 42}, {translateY: 1492}],
|
||||
left: 42,
|
||||
top: 1492,
|
||||
},
|
||||
@@ -767,7 +786,7 @@ describe('Animated tests', () => {
|
||||
it('should removeAll', () => {
|
||||
const value1 = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
[1,2,3,4].forEach(() => value1.addListener(listener));
|
||||
[1, 2, 3, 4].forEach(() => value1.addListener(listener));
|
||||
value1.setValue(42);
|
||||
expect(listener.mock.calls.length).toBe(4);
|
||||
expect(listener).toBeCalledWith({value: 42});
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const ClassComponentMock = class {};
|
||||
@@ -39,7 +41,6 @@ function createAndMountComponent(ComponentClass, props) {
|
||||
}
|
||||
|
||||
describe('Native Animated', () => {
|
||||
|
||||
const nativeAnimatedModule = require('NativeModules').NativeAnimatedModule;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -64,7 +65,11 @@ describe('Native Animated', () => {
|
||||
describe('Animated Value', () => {
|
||||
it('proxies `setValue` correctly', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
Animated.timing(anim, {toValue: 10, duration: 1000, useNativeDriver: true}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 1000,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
const c = createAndMountComponent(Animated.View, {
|
||||
style: {
|
||||
@@ -82,7 +87,10 @@ describe('Native Animated', () => {
|
||||
|
||||
anim.setValue(0.5);
|
||||
|
||||
expect(nativeAnimatedModule.setAnimatedNodeValue).toBeCalledWith(expect.any(Number), 0.5);
|
||||
expect(nativeAnimatedModule.setAnimatedNodeValue).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
0.5,
|
||||
);
|
||||
expect(c.refs.node.setNativeProps).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -101,8 +109,10 @@ describe('Native Animated', () => {
|
||||
{type: 'value', value: 0, offset: 10},
|
||||
);
|
||||
anim.setOffset(20);
|
||||
expect(nativeAnimatedModule.setAnimatedNodeOffset)
|
||||
.toBeCalledWith(expect.any(Number), 20);
|
||||
expect(nativeAnimatedModule.setAnimatedNodeOffset).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
20,
|
||||
);
|
||||
});
|
||||
|
||||
it('should flatten offset', () => {
|
||||
@@ -119,8 +129,9 @@ describe('Native Animated', () => {
|
||||
{type: 'value', value: 0, offset: 0},
|
||||
);
|
||||
anim.flattenOffset();
|
||||
expect(nativeAnimatedModule.flattenAnimatedNodeOffset)
|
||||
.toBeCalledWith(expect.any(Number));
|
||||
expect(nativeAnimatedModule.flattenAnimatedNodeOffset).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
|
||||
it('should extract offset', () => {
|
||||
@@ -137,8 +148,9 @@ describe('Native Animated', () => {
|
||||
{type: 'value', value: 0, offset: 0},
|
||||
);
|
||||
anim.extractOffset();
|
||||
expect(nativeAnimatedModule.extractAnimatedNodeOffset)
|
||||
.toBeCalledWith(expect.any(Number));
|
||||
expect(nativeAnimatedModule.extractAnimatedNodeOffset).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,33 +160,35 @@ describe('Native Animated', () => {
|
||||
value1.__makeNative();
|
||||
const listener = jest.fn();
|
||||
const id = value1.addListener(listener);
|
||||
expect(nativeAnimatedModule.startListeningToAnimatedNodeValue)
|
||||
.toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
expect(
|
||||
nativeAnimatedModule.startListeningToAnimatedNodeValue,
|
||||
).toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit(
|
||||
'onAnimatedValueUpdate',
|
||||
{value: 42, tag: value1.__getNativeTag()},
|
||||
);
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit('onAnimatedValueUpdate', {
|
||||
value: 42,
|
||||
tag: value1.__getNativeTag(),
|
||||
});
|
||||
expect(listener).toHaveBeenCalledTimes(1);
|
||||
expect(listener).toBeCalledWith({value: 42});
|
||||
expect(value1.__getValue()).toBe(42);
|
||||
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit(
|
||||
'onAnimatedValueUpdate',
|
||||
{value: 7, tag: value1.__getNativeTag()},
|
||||
);
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit('onAnimatedValueUpdate', {
|
||||
value: 7,
|
||||
tag: value1.__getNativeTag(),
|
||||
});
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
expect(listener).toBeCalledWith({value: 7});
|
||||
expect(value1.__getValue()).toBe(7);
|
||||
|
||||
value1.removeListener(id);
|
||||
expect(nativeAnimatedModule.stopListeningToAnimatedNodeValue)
|
||||
.toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
expect(
|
||||
nativeAnimatedModule.stopListeningToAnimatedNodeValue,
|
||||
).toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit(
|
||||
'onAnimatedValueUpdate',
|
||||
{value: 1492, tag: value1.__getNativeTag()},
|
||||
);
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit('onAnimatedValueUpdate', {
|
||||
value: 1492,
|
||||
tag: value1.__getNativeTag(),
|
||||
});
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
expect(value1.__getValue()).toBe(7);
|
||||
});
|
||||
@@ -183,25 +197,27 @@ describe('Native Animated', () => {
|
||||
const value1 = new Animated.Value(0);
|
||||
value1.__makeNative();
|
||||
const listener = jest.fn();
|
||||
[1,2,3,4].forEach(() => value1.addListener(listener));
|
||||
expect(nativeAnimatedModule.startListeningToAnimatedNodeValue)
|
||||
.toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
[1, 2, 3, 4].forEach(() => value1.addListener(listener));
|
||||
expect(
|
||||
nativeAnimatedModule.startListeningToAnimatedNodeValue,
|
||||
).toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit(
|
||||
'onAnimatedValueUpdate',
|
||||
{value: 42, tag: value1.__getNativeTag()},
|
||||
);
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit('onAnimatedValueUpdate', {
|
||||
value: 42,
|
||||
tag: value1.__getNativeTag(),
|
||||
});
|
||||
expect(listener).toHaveBeenCalledTimes(4);
|
||||
expect(listener).toBeCalledWith({value: 42});
|
||||
|
||||
value1.removeAllListeners();
|
||||
expect(nativeAnimatedModule.stopListeningToAnimatedNodeValue)
|
||||
.toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
expect(
|
||||
nativeAnimatedModule.stopListeningToAnimatedNodeValue,
|
||||
).toHaveBeenCalledWith(value1.__getNativeTag());
|
||||
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit(
|
||||
'onAnimatedValueUpdate',
|
||||
{value: 7, tag: value1.__getNativeTag()},
|
||||
);
|
||||
NativeAnimatedHelper.nativeEventEmitter.emit('onAnimatedValueUpdate', {
|
||||
value: 7,
|
||||
tag: value1.__getNativeTag(),
|
||||
});
|
||||
expect(listener).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
@@ -210,15 +226,17 @@ describe('Native Animated', () => {
|
||||
it('should map events', () => {
|
||||
const value = new Animated.Value(0);
|
||||
value.__makeNative();
|
||||
const event = Animated.event(
|
||||
[{nativeEvent: {state: {foo: value}}}],
|
||||
{useNativeDriver: true},
|
||||
);
|
||||
const event = Animated.event([{nativeEvent: {state: {foo: value}}}], {
|
||||
useNativeDriver: true,
|
||||
});
|
||||
const c = createAndMountComponent(Animated.View, {onTouchMove: event});
|
||||
expect(nativeAnimatedModule.addAnimatedEventToView).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
'onTouchMove',
|
||||
{nativeEventPath: ['state', 'foo'], animatedValueTag: value.__getNativeTag()},
|
||||
{
|
||||
nativeEventPath: ['state', 'foo'],
|
||||
animatedValueTag: value.__getNativeTag(),
|
||||
},
|
||||
);
|
||||
|
||||
c.componentWillUnmount();
|
||||
@@ -232,12 +250,12 @@ describe('Native Animated', () => {
|
||||
it('should throw on invalid event path', () => {
|
||||
const value = new Animated.Value(0);
|
||||
value.__makeNative();
|
||||
const event = Animated.event(
|
||||
[{notNativeEvent: {foo: value}}],
|
||||
{useNativeDriver: true},
|
||||
);
|
||||
expect(() => createAndMountComponent(Animated.View, {onTouchMove: event}))
|
||||
.toThrowError(/nativeEvent/);
|
||||
const event = Animated.event([{notNativeEvent: {foo: value}}], {
|
||||
useNativeDriver: true,
|
||||
});
|
||||
expect(() =>
|
||||
createAndMountComponent(Animated.View, {onTouchMove: event}),
|
||||
).toThrowError(/nativeEvent/);
|
||||
expect(nativeAnimatedModule.addAnimatedEventToView).not.toBeCalled();
|
||||
});
|
||||
|
||||
@@ -245,10 +263,10 @@ describe('Native Animated', () => {
|
||||
const value = new Animated.Value(0);
|
||||
value.__makeNative();
|
||||
const listener = jest.fn();
|
||||
const event = Animated.event(
|
||||
[{nativeEvent: {foo: value}}],
|
||||
{useNativeDriver: true, listener},
|
||||
);
|
||||
const event = Animated.event([{nativeEvent: {foo: value}}], {
|
||||
useNativeDriver: true,
|
||||
listener,
|
||||
});
|
||||
const handler = event.__getHandler();
|
||||
handler({foo: 42});
|
||||
expect(listener).toHaveBeenCalledTimes(1);
|
||||
@@ -265,21 +283,34 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
Animated.timing(anim, {toValue: 10, duration: 1000, useNativeDriver: true}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 1000,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
c.componentWillUnmount();
|
||||
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toHaveBeenCalledTimes(3);
|
||||
expect(nativeAnimatedModule.connectAnimatedNodes).toHaveBeenCalledTimes(2);
|
||||
expect(nativeAnimatedModule.connectAnimatedNodes).toHaveBeenCalledTimes(
|
||||
2,
|
||||
);
|
||||
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
{type: 'frames', frames: expect.any(Array), toValue: expect.any(Number), iterations: 1},
|
||||
expect.any(Function)
|
||||
{
|
||||
type: 'frames',
|
||||
frames: expect.any(Array),
|
||||
toValue: expect.any(Number),
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
expect(nativeAnimatedModule.disconnectAnimatedNodes).toHaveBeenCalledTimes(2);
|
||||
expect(
|
||||
nativeAnimatedModule.disconnectAnimatedNodes,
|
||||
).toHaveBeenCalledTimes(2);
|
||||
expect(nativeAnimatedModule.dropAnimatedNode).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
@@ -291,14 +322,24 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
Animated.timing(anim, {toValue: 10, duration: 1000, useNativeDriver: true}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 1000,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), {type: 'value', value: 0, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), {type: 'style', style: {opacity: expect.any(Number)}});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), {type: 'props', props: {style: expect.any(Number)}});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'value', value: 0, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'style', style: {opacity: expect.any(Number)}},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'props', props: {style: expect.any(Number)}},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for Animated.add nodes', () => {
|
||||
@@ -318,19 +359,23 @@ describe('Native Animated', () => {
|
||||
{type: 'addition', input: expect.any(Array)},
|
||||
);
|
||||
const additionCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'addition'
|
||||
call => call[1].type === 'addition',
|
||||
);
|
||||
expect(additionCalls.length).toBe(1);
|
||||
const additionCall = additionCalls[0];
|
||||
const additionNodeTag = additionCall[0];
|
||||
const additionConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === additionNodeTag
|
||||
call => call[1] === additionNodeTag,
|
||||
);
|
||||
expect(additionConnectionCalls.length).toBe(2);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(additionCall[1].input[0], {type: 'value', value: 1, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(additionCall[1].input[1], {type: 'value', value: 2, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
additionCall[1].input[0],
|
||||
{type: 'value', value: 1, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
additionCall[1].input[1],
|
||||
{type: 'value', value: 2, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for Animated.subtract nodes', () => {
|
||||
@@ -350,19 +395,23 @@ describe('Native Animated', () => {
|
||||
{type: 'subtraction', input: expect.any(Array)},
|
||||
);
|
||||
const subtractionCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'subtraction'
|
||||
call => call[1].type === 'subtraction',
|
||||
);
|
||||
expect(subtractionCalls.length).toBe(1);
|
||||
const subtractionCall = subtractionCalls[0];
|
||||
const subtractionNodeTag = subtractionCall[0];
|
||||
const subtractionConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === subtractionNodeTag
|
||||
call => call[1] === subtractionNodeTag,
|
||||
);
|
||||
expect(subtractionConnectionCalls.length).toBe(2);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(subtractionCall[1].input[0], {type: 'value', value: 2, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(subtractionCall[1].input[1], {type: 'value', value: 1, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
subtractionCall[1].input[0],
|
||||
{type: 'value', value: 2, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
subtractionCall[1].input[1],
|
||||
{type: 'value', value: 1, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for Animated.multiply nodes', () => {
|
||||
@@ -382,19 +431,23 @@ describe('Native Animated', () => {
|
||||
{type: 'multiplication', input: expect.any(Array)},
|
||||
);
|
||||
const multiplicationCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'multiplication'
|
||||
call => call[1].type === 'multiplication',
|
||||
);
|
||||
expect(multiplicationCalls.length).toBe(1);
|
||||
const multiplicationCall = multiplicationCalls[0];
|
||||
const multiplicationNodeTag = multiplicationCall[0];
|
||||
const multiplicationConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === multiplicationNodeTag
|
||||
call => call[1] === multiplicationNodeTag,
|
||||
);
|
||||
expect(multiplicationConnectionCalls.length).toBe(2);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(multiplicationCall[1].input[0], {type: 'value', value: 2, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(multiplicationCall[1].input[1], {type: 'value', value: 1, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
multiplicationCall[1].input[0],
|
||||
{type: 'value', value: 2, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
multiplicationCall[1].input[1],
|
||||
{type: 'value', value: 1, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for Animated.divide nodes', () => {
|
||||
@@ -409,22 +462,28 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), {type: 'division', input: expect.any(Array)});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'division', input: expect.any(Array)},
|
||||
);
|
||||
const divisionCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'division'
|
||||
call => call[1].type === 'division',
|
||||
);
|
||||
expect(divisionCalls.length).toBe(1);
|
||||
const divisionCall = divisionCalls[0];
|
||||
const divisionNodeTag = divisionCall[0];
|
||||
const divisionConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === divisionNodeTag
|
||||
call => call[1] === divisionNodeTag,
|
||||
);
|
||||
expect(divisionConnectionCalls.length).toBe(2);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(divisionCall[1].input[0], {type: 'value', value: 4, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(divisionCall[1].input[1], {type: 'value', value: 2, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
divisionCall[1].input[0],
|
||||
{type: 'value', value: 4, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
divisionCall[1].input[1],
|
||||
{type: 'value', value: 2, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for Animated.modulo nodes', () => {
|
||||
@@ -442,17 +501,19 @@ describe('Native Animated', () => {
|
||||
{type: 'modulus', modulus: 4, input: expect.any(Number)},
|
||||
);
|
||||
const moduloCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'modulus'
|
||||
call => call[1].type === 'modulus',
|
||||
);
|
||||
expect(moduloCalls.length).toBe(1);
|
||||
const moduloCall = moduloCalls[0];
|
||||
const moduloNodeTag = moduloCall[0];
|
||||
const moduloConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === moduloNodeTag
|
||||
call => call[1] === moduloNodeTag,
|
||||
);
|
||||
expect(moduloConnectionCalls.length).toBe(1);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(moduloCall[1].input, {type: 'value', value: 4, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
moduloCall[1].input,
|
||||
{type: 'value', value: 4, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for interpolate() nodes', () => {
|
||||
@@ -470,23 +531,28 @@ describe('Native Animated', () => {
|
||||
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'value', value: 10, offset: 0}
|
||||
{type: 'value', value: 10, offset: 0},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), {
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{
|
||||
type: 'interpolation',
|
||||
inputRange: [10, 20],
|
||||
outputRange: [0, 1],
|
||||
extrapolateLeft: 'extend',
|
||||
extrapolateRight: 'extend',
|
||||
});
|
||||
},
|
||||
);
|
||||
const interpolationNodeTag = nativeAnimatedModule.createAnimatedNode.mock.calls.find(
|
||||
(call) => call[1].type === 'interpolation'
|
||||
call => call[1].type === 'interpolation',
|
||||
)[0];
|
||||
const valueNodeTag = nativeAnimatedModule.createAnimatedNode.mock.calls.find(
|
||||
(call) => call[1].type === 'value'
|
||||
call => call[1].type === 'value',
|
||||
)[0];
|
||||
expect(nativeAnimatedModule.connectAnimatedNodes).toBeCalledWith(valueNodeTag, interpolationNodeTag);
|
||||
expect(nativeAnimatedModule.connectAnimatedNodes).toBeCalledWith(
|
||||
valueNodeTag,
|
||||
interpolationNodeTag,
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid graph description for transform nodes', () => {
|
||||
@@ -503,15 +569,18 @@ describe('Native Animated', () => {
|
||||
expect.any(Number),
|
||||
{
|
||||
type: 'transform',
|
||||
transforms: [{
|
||||
nodeTag: expect.any(Number),
|
||||
property: 'translateX',
|
||||
type: 'animated',
|
||||
}, {
|
||||
value: 2,
|
||||
property: 'scale',
|
||||
type: 'static',
|
||||
}],
|
||||
transforms: [
|
||||
{
|
||||
nodeTag: expect.any(Number),
|
||||
property: 'translateX',
|
||||
type: 'animated',
|
||||
},
|
||||
{
|
||||
value: 2,
|
||||
property: 'scale',
|
||||
type: 'static',
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -531,20 +600,22 @@ describe('Native Animated', () => {
|
||||
{type: 'diffclamp', input: expect.any(Number), max: 20, min: 0},
|
||||
);
|
||||
const diffClampCalls = nativeAnimatedModule.createAnimatedNode.mock.calls.filter(
|
||||
(call) => call[1].type === 'diffclamp'
|
||||
call => call[1].type === 'diffclamp',
|
||||
);
|
||||
expect(diffClampCalls.length).toBe(1);
|
||||
const diffClampCall = diffClampCalls[0];
|
||||
const diffClampNodeTag = diffClampCall[0];
|
||||
const diffClampConnectionCalls = nativeAnimatedModule.connectAnimatedNodes.mock.calls.filter(
|
||||
(call) => call[1] === diffClampNodeTag
|
||||
call => call[1] === diffClampNodeTag,
|
||||
);
|
||||
expect(diffClampConnectionCalls.length).toBe(1);
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(diffClampCall[1].input, {type: 'value', value: 2, offset: 0});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
diffClampCall[1].input,
|
||||
{type: 'value', value: 2, offset: 0},
|
||||
);
|
||||
});
|
||||
|
||||
it('doesn\'t call into native API if useNativeDriver is set to false', () => {
|
||||
it("doesn't call into native API if useNativeDriver is set to false", () => {
|
||||
const anim = new Animated.Value(0);
|
||||
|
||||
const c = createAndMountComponent(Animated.View, {
|
||||
@@ -553,7 +624,11 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
Animated.timing(anim, {toValue: 10, duration: 1000, useNativeDriver: false}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 1000,
|
||||
useNativeDriver: false,
|
||||
}).start();
|
||||
|
||||
c.componentWillUnmount();
|
||||
|
||||
@@ -569,10 +644,18 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
Animated.timing(anim, {toValue: 10, duration: 50, useNativeDriver: true}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 50,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
jest.runAllTimers();
|
||||
|
||||
Animated.timing(anim, {toValue: 4, duration: 500, useNativeDriver: false}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 4,
|
||||
duration: 500,
|
||||
useNativeDriver: false,
|
||||
}).start();
|
||||
expect(jest.runAllTimers).toThrow();
|
||||
});
|
||||
|
||||
@@ -585,7 +668,11 @@ describe('Native Animated', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const animation = Animated.timing(anim, {toValue: 10, duration: 50, useNativeDriver: true});
|
||||
const animation = Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 50,
|
||||
useNativeDriver: true,
|
||||
});
|
||||
expect(animation.start).toThrowError(/left/);
|
||||
});
|
||||
|
||||
@@ -603,29 +690,47 @@ describe('Native Animated', () => {
|
||||
removeClippedSubviews: true,
|
||||
});
|
||||
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), { type: 'style', style: { opacity: expect.any(Number) }});
|
||||
expect(nativeAnimatedModule.createAnimatedNode)
|
||||
.toBeCalledWith(expect.any(Number), { type: 'props', props: { style: expect.any(Number) }});
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'style', style: {opacity: expect.any(Number)}},
|
||||
);
|
||||
expect(nativeAnimatedModule.createAnimatedNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
{type: 'props', props: {style: expect.any(Number)}},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Animations', () => {
|
||||
it('sends a valid timing animation description', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
Animated.timing(anim, {toValue: 10, duration: 1000, useNativeDriver: true}).start();
|
||||
Animated.timing(anim, {
|
||||
toValue: 10,
|
||||
duration: 1000,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
{type: 'frames', frames: expect.any(Array), toValue: expect.any(Number), iterations: 1},
|
||||
expect.any(Function)
|
||||
{
|
||||
type: 'frames',
|
||||
frames: expect.any(Array),
|
||||
toValue: expect.any(Number),
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid spring animation description', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
Animated.spring(anim, {toValue: 10, friction: 5, tension: 164, useNativeDriver: true}).start();
|
||||
Animated.spring(anim, {
|
||||
toValue: 10,
|
||||
friction: 5,
|
||||
tension: 164,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
@@ -641,7 +746,7 @@ describe('Native Animated', () => {
|
||||
toValue: 10,
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
Animated.spring(anim, {
|
||||
@@ -649,7 +754,7 @@ describe('Native Animated', () => {
|
||||
stiffness: 1000,
|
||||
damping: 500,
|
||||
mass: 3,
|
||||
useNativeDriver: true
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
@@ -666,10 +771,15 @@ describe('Native Animated', () => {
|
||||
toValue: 10,
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
Animated.spring(anim, {toValue: 10, bounciness: 8, speed: 10, useNativeDriver: true}).start();
|
||||
Animated.spring(anim, {
|
||||
toValue: 10,
|
||||
bounciness: 8,
|
||||
speed: 10,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
@@ -685,49 +795,67 @@ describe('Native Animated', () => {
|
||||
toValue: 10,
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a valid decay animation description', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
Animated.decay(anim, {velocity: 10, deceleration: 0.1, useNativeDriver: true}).start();
|
||||
Animated.decay(anim, {
|
||||
velocity: 10,
|
||||
deceleration: 0.1,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
{type: 'decay', deceleration: 0.1, velocity: 10, iterations: 1},
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
it('works with Animated.loop', () => {
|
||||
const anim = new Animated.Value(0);
|
||||
Animated.loop(
|
||||
Animated.decay(anim, {velocity: 10, deceleration: 0.1, useNativeDriver: true}),
|
||||
{ iterations: 10 },
|
||||
Animated.decay(anim, {
|
||||
velocity: 10,
|
||||
deceleration: 0.1,
|
||||
useNativeDriver: true,
|
||||
}),
|
||||
{iterations: 10},
|
||||
).start();
|
||||
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
{type: 'decay', deceleration: 0.1, velocity: 10, iterations: 10},
|
||||
expect.any(Function)
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
it('sends stopAnimation command to native', () => {
|
||||
const value = new Animated.Value(0);
|
||||
const animation = Animated.timing(value, {toValue: 10, duration: 50, useNativeDriver: true});
|
||||
const animation = Animated.timing(value, {
|
||||
toValue: 10,
|
||||
duration: 50,
|
||||
useNativeDriver: true,
|
||||
});
|
||||
|
||||
animation.start();
|
||||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
expect.any(Number),
|
||||
expect.any(Number),
|
||||
{type: 'frames', frames: expect.any(Array), toValue: expect.any(Number), iterations: 1},
|
||||
expect.any(Function)
|
||||
{
|
||||
type: 'frames',
|
||||
frames: expect.any(Array),
|
||||
toValue: expect.any(Number),
|
||||
iterations: 1,
|
||||
},
|
||||
expect.any(Function),
|
||||
);
|
||||
const animationId = nativeAnimatedModule.startAnimatingNode.mock.calls[0][0];
|
||||
const animationId =
|
||||
nativeAnimatedModule.startAnimatingNode.mock.calls[0][0];
|
||||
|
||||
animation.stop();
|
||||
expect(nativeAnimatedModule.stopAnimation).toBeCalledWith(animationId);
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Easing = require('Easing');
|
||||
@@ -88,23 +90,363 @@ describe('Easing', () => {
|
||||
}
|
||||
|
||||
const Samples = {
|
||||
in_quad: [0,0.0030864197530864196,0.012345679012345678,0.027777777777777776,0.04938271604938271,0.0771604938271605,0.1111111111111111,0.15123456790123457,0.19753086419753085,0.25,0.308641975308642,0.37345679012345684,0.4444444444444444,0.5216049382716049,0.6049382716049383,0.6944444444444445,0.7901234567901234,0.8919753086419753,1],
|
||||
out_quad: [0,0.10802469135802469,0.20987654320987653,0.3055555555555555,0.3950617283950617,0.47839506172839513,0.5555555555555556,0.6265432098765432,0.691358024691358,0.75,0.8024691358024691,0.8487654320987654,0.888888888888889,0.9228395061728394,0.9506172839506174,0.9722222222222221,0.9876543209876543,0.9969135802469136,1],
|
||||
inOut_quad: [0,0.006172839506172839,0.024691358024691357,0.05555555555555555,0.09876543209876543,0.154320987654321,0.2222222222222222,0.30246913580246915,0.3950617283950617,0.5,0.6049382716049383,0.697530864197531,0.7777777777777777,0.845679012345679,0.9012345679012346,0.9444444444444444,0.9753086419753086,0.9938271604938271,1],
|
||||
in_cubic: [0,0.00017146776406035664,0.0013717421124828531,0.004629629629629629,0.010973936899862825,0.021433470507544586,0.037037037037037035,0.05881344307270234,0.0877914951989026,0.125,0.1714677640603567,0.22822359396433475,0.2962962962962963,0.37671467764060357,0.4705075445816187,0.5787037037037038,0.7023319615912208,0.8424211248285322,1],
|
||||
out_cubic: [0,0.15757887517146785,0.2976680384087792,0.42129629629629617,0.5294924554183813,0.6232853223593964,0.7037037037037036,0.7717764060356652,0.8285322359396433,0.875,0.9122085048010974,0.9411865569272977,0.9629629629629629,0.9785665294924554,0.9890260631001372,0.9953703703703703,0.9986282578875172,0.9998285322359396,1],
|
||||
inOut_cubic: [0,0.0006858710562414266,0.0054869684499314125,0.018518518518518517,0.0438957475994513,0.08573388203017834,0.14814814814814814,0.23525377229080935,0.3511659807956104,0.5,0.6488340192043895,0.7647462277091908,0.8518518518518519,0.9142661179698217,0.9561042524005487,0.9814814814814815,0.9945130315500685,0.9993141289437586,1],
|
||||
in_sin: [0,0.003805301908254455,0.01519224698779198,0.03407417371093169,0.06030737921409157,0.09369221296335006,0.1339745962155613,0.1808479557110082,0.233955556881022,0.2928932188134524,0.35721239031346064,0.42642356364895384,0.4999999999999999,0.5773817382593005,0.6579798566743311,0.7411809548974793,0.8263518223330696,0.9128442572523416,0.9999999999999999],
|
||||
out_sin: [0,0.08715574274765817,0.17364817766693033,0.25881904510252074,0.3420201433256687,0.42261826174069944,0.49999999999999994,0.573576436351046,0.6427876096865393,0.7071067811865475,0.766044443118978,0.8191520442889918,0.8660254037844386,0.9063077870366499,0.9396926207859083,0.9659258262890683,0.984807753012208,0.9961946980917455,1],
|
||||
inOut_sin: [0,0.00759612349389599,0.030153689607045786,0.06698729810778065,0.116977778440511,0.17860619515673032,0.24999999999999994,0.32898992833716556,0.4131759111665348,0.49999999999999994,0.5868240888334652,0.6710100716628343,0.7499999999999999,0.8213938048432696,0.883022221559489,0.9330127018922194,0.9698463103929542,0.9924038765061041,1],
|
||||
in_exp: [0,0.0014352875901128893,0.002109491677524035,0.0031003926796253885,0.004556754060844206,0.006697218616039631,0.009843133202303688,0.014466792379488908,0.021262343752724643,0.03125,0.045929202883612456,0.06750373368076916,0.09921256574801243,0.1458161299470146,0.2143109957132682,0.31498026247371835,0.46293735614364506,0.6803950000871883,1],
|
||||
out_exp: [0,0.31960499991281155,0.5370626438563548,0.6850197375262816,0.7856890042867318,0.8541838700529854,0.9007874342519875,0.9324962663192309,0.9540707971163875,0.96875,0.9787376562472754,0.9855332076205111,0.9901568667976963,0.9933027813839603,0.9954432459391558,0.9968996073203746,0.9978905083224759,0.9985647124098871,1],
|
||||
inOut_exp: [0,0.0010547458387620175,0.002278377030422103,0.004921566601151844,0.010631171876362321,0.022964601441806228,0.049606282874006216,0.1071554978566341,0.23146867807182253,0.5,0.7685313219281775,0.892844502143366,0.9503937171259937,0.9770353985581938,0.9893688281236377,0.9950784333988482,0.9977216229695779,0.998945254161238,1],
|
||||
in_circle: [0,0.0015444024660317135,0.006192010000093506,0.013986702816730645,0.025003956956430873,0.03935464078941209,0.057190958417936644,0.07871533601238889,0.10419358352238339,0.1339745962155614,0.1685205807169019,0.20845517506805522,0.2546440075000701,0.3083389112228482,0.37146063894529113,0.4472292016074334,0.5418771527091488,0.6713289009389102,1],
|
||||
out_circle: [0,0.3286710990610898,0.45812284729085123,0.5527707983925666,0.6285393610547089,0.6916610887771518,0.7453559924999298,0.7915448249319448,0.8314794192830981,0.8660254037844386,0.8958064164776166,0.9212846639876111,0.9428090415820634,0.9606453592105879,0.9749960430435691,0.9860132971832694,0.9938079899999065,0.9984555975339683,1],
|
||||
inOut_circle: [0,0.003096005000046753,0.012501978478215436,0.028595479208968322,0.052096791761191696,0.08426029035845095,0.12732200375003505,0.18573031947264557,0.2709385763545744,0.5,0.7290614236454256,0.8142696805273546,0.8726779962499649,0.915739709641549,0.9479032082388084,0.9714045207910317,0.9874980215217846,0.9969039949999532,1],
|
||||
in_back_: [0,-0.004788556241426612,-0.017301289437585736,-0.0347587962962963,-0.05438167352537723,-0.07339051783264748,-0.08900592592592595,-0.09844849451303156,-0.0989388203017833,-0.08769750000000004,-0.06194513031550073,-0.018902307956104283,0.044210370370370254,0.13017230795610413,0.2417629080932785,0.3817615740740742,0.5529477091906719,0.7581007167352535,0.9999999999999998],
|
||||
out_back_: [2.220446049250313e-16,0.24189928326474652,0.44705229080932807,0.6182384259259258,0.7582370919067215,0.8698276920438959,0.9557896296296297,1.0189023079561044,1.0619451303155008,1.0876975,1.0989388203017834,1.0984484945130315,1.089005925925926,1.0733905178326475,1.0543816735253773,1.0347587962962963,1.0173012894375857,1.0047885562414267,1],
|
||||
in_quad: [
|
||||
0,
|
||||
0.0030864197530864196,
|
||||
0.012345679012345678,
|
||||
0.027777777777777776,
|
||||
0.04938271604938271,
|
||||
0.0771604938271605,
|
||||
0.1111111111111111,
|
||||
0.15123456790123457,
|
||||
0.19753086419753085,
|
||||
0.25,
|
||||
0.308641975308642,
|
||||
0.37345679012345684,
|
||||
0.4444444444444444,
|
||||
0.5216049382716049,
|
||||
0.6049382716049383,
|
||||
0.6944444444444445,
|
||||
0.7901234567901234,
|
||||
0.8919753086419753,
|
||||
1,
|
||||
],
|
||||
out_quad: [
|
||||
0,
|
||||
0.10802469135802469,
|
||||
0.20987654320987653,
|
||||
0.3055555555555555,
|
||||
0.3950617283950617,
|
||||
0.47839506172839513,
|
||||
0.5555555555555556,
|
||||
0.6265432098765432,
|
||||
0.691358024691358,
|
||||
0.75,
|
||||
0.8024691358024691,
|
||||
0.8487654320987654,
|
||||
0.888888888888889,
|
||||
0.9228395061728394,
|
||||
0.9506172839506174,
|
||||
0.9722222222222221,
|
||||
0.9876543209876543,
|
||||
0.9969135802469136,
|
||||
1,
|
||||
],
|
||||
inOut_quad: [
|
||||
0,
|
||||
0.006172839506172839,
|
||||
0.024691358024691357,
|
||||
0.05555555555555555,
|
||||
0.09876543209876543,
|
||||
0.154320987654321,
|
||||
0.2222222222222222,
|
||||
0.30246913580246915,
|
||||
0.3950617283950617,
|
||||
0.5,
|
||||
0.6049382716049383,
|
||||
0.697530864197531,
|
||||
0.7777777777777777,
|
||||
0.845679012345679,
|
||||
0.9012345679012346,
|
||||
0.9444444444444444,
|
||||
0.9753086419753086,
|
||||
0.9938271604938271,
|
||||
1,
|
||||
],
|
||||
in_cubic: [
|
||||
0,
|
||||
0.00017146776406035664,
|
||||
0.0013717421124828531,
|
||||
0.004629629629629629,
|
||||
0.010973936899862825,
|
||||
0.021433470507544586,
|
||||
0.037037037037037035,
|
||||
0.05881344307270234,
|
||||
0.0877914951989026,
|
||||
0.125,
|
||||
0.1714677640603567,
|
||||
0.22822359396433475,
|
||||
0.2962962962962963,
|
||||
0.37671467764060357,
|
||||
0.4705075445816187,
|
||||
0.5787037037037038,
|
||||
0.7023319615912208,
|
||||
0.8424211248285322,
|
||||
1,
|
||||
],
|
||||
out_cubic: [
|
||||
0,
|
||||
0.15757887517146785,
|
||||
0.2976680384087792,
|
||||
0.42129629629629617,
|
||||
0.5294924554183813,
|
||||
0.6232853223593964,
|
||||
0.7037037037037036,
|
||||
0.7717764060356652,
|
||||
0.8285322359396433,
|
||||
0.875,
|
||||
0.9122085048010974,
|
||||
0.9411865569272977,
|
||||
0.9629629629629629,
|
||||
0.9785665294924554,
|
||||
0.9890260631001372,
|
||||
0.9953703703703703,
|
||||
0.9986282578875172,
|
||||
0.9998285322359396,
|
||||
1,
|
||||
],
|
||||
inOut_cubic: [
|
||||
0,
|
||||
0.0006858710562414266,
|
||||
0.0054869684499314125,
|
||||
0.018518518518518517,
|
||||
0.0438957475994513,
|
||||
0.08573388203017834,
|
||||
0.14814814814814814,
|
||||
0.23525377229080935,
|
||||
0.3511659807956104,
|
||||
0.5,
|
||||
0.6488340192043895,
|
||||
0.7647462277091908,
|
||||
0.8518518518518519,
|
||||
0.9142661179698217,
|
||||
0.9561042524005487,
|
||||
0.9814814814814815,
|
||||
0.9945130315500685,
|
||||
0.9993141289437586,
|
||||
1,
|
||||
],
|
||||
in_sin: [
|
||||
0,
|
||||
0.003805301908254455,
|
||||
0.01519224698779198,
|
||||
0.03407417371093169,
|
||||
0.06030737921409157,
|
||||
0.09369221296335006,
|
||||
0.1339745962155613,
|
||||
0.1808479557110082,
|
||||
0.233955556881022,
|
||||
0.2928932188134524,
|
||||
0.35721239031346064,
|
||||
0.42642356364895384,
|
||||
0.4999999999999999,
|
||||
0.5773817382593005,
|
||||
0.6579798566743311,
|
||||
0.7411809548974793,
|
||||
0.8263518223330696,
|
||||
0.9128442572523416,
|
||||
0.9999999999999999,
|
||||
],
|
||||
out_sin: [
|
||||
0,
|
||||
0.08715574274765817,
|
||||
0.17364817766693033,
|
||||
0.25881904510252074,
|
||||
0.3420201433256687,
|
||||
0.42261826174069944,
|
||||
0.49999999999999994,
|
||||
0.573576436351046,
|
||||
0.6427876096865393,
|
||||
0.7071067811865475,
|
||||
0.766044443118978,
|
||||
0.8191520442889918,
|
||||
0.8660254037844386,
|
||||
0.9063077870366499,
|
||||
0.9396926207859083,
|
||||
0.9659258262890683,
|
||||
0.984807753012208,
|
||||
0.9961946980917455,
|
||||
1,
|
||||
],
|
||||
inOut_sin: [
|
||||
0,
|
||||
0.00759612349389599,
|
||||
0.030153689607045786,
|
||||
0.06698729810778065,
|
||||
0.116977778440511,
|
||||
0.17860619515673032,
|
||||
0.24999999999999994,
|
||||
0.32898992833716556,
|
||||
0.4131759111665348,
|
||||
0.49999999999999994,
|
||||
0.5868240888334652,
|
||||
0.6710100716628343,
|
||||
0.7499999999999999,
|
||||
0.8213938048432696,
|
||||
0.883022221559489,
|
||||
0.9330127018922194,
|
||||
0.9698463103929542,
|
||||
0.9924038765061041,
|
||||
1,
|
||||
],
|
||||
in_exp: [
|
||||
0,
|
||||
0.0014352875901128893,
|
||||
0.002109491677524035,
|
||||
0.0031003926796253885,
|
||||
0.004556754060844206,
|
||||
0.006697218616039631,
|
||||
0.009843133202303688,
|
||||
0.014466792379488908,
|
||||
0.021262343752724643,
|
||||
0.03125,
|
||||
0.045929202883612456,
|
||||
0.06750373368076916,
|
||||
0.09921256574801243,
|
||||
0.1458161299470146,
|
||||
0.2143109957132682,
|
||||
0.31498026247371835,
|
||||
0.46293735614364506,
|
||||
0.6803950000871883,
|
||||
1,
|
||||
],
|
||||
out_exp: [
|
||||
0,
|
||||
0.31960499991281155,
|
||||
0.5370626438563548,
|
||||
0.6850197375262816,
|
||||
0.7856890042867318,
|
||||
0.8541838700529854,
|
||||
0.9007874342519875,
|
||||
0.9324962663192309,
|
||||
0.9540707971163875,
|
||||
0.96875,
|
||||
0.9787376562472754,
|
||||
0.9855332076205111,
|
||||
0.9901568667976963,
|
||||
0.9933027813839603,
|
||||
0.9954432459391558,
|
||||
0.9968996073203746,
|
||||
0.9978905083224759,
|
||||
0.9985647124098871,
|
||||
1,
|
||||
],
|
||||
inOut_exp: [
|
||||
0,
|
||||
0.0010547458387620175,
|
||||
0.002278377030422103,
|
||||
0.004921566601151844,
|
||||
0.010631171876362321,
|
||||
0.022964601441806228,
|
||||
0.049606282874006216,
|
||||
0.1071554978566341,
|
||||
0.23146867807182253,
|
||||
0.5,
|
||||
0.7685313219281775,
|
||||
0.892844502143366,
|
||||
0.9503937171259937,
|
||||
0.9770353985581938,
|
||||
0.9893688281236377,
|
||||
0.9950784333988482,
|
||||
0.9977216229695779,
|
||||
0.998945254161238,
|
||||
1,
|
||||
],
|
||||
in_circle: [
|
||||
0,
|
||||
0.0015444024660317135,
|
||||
0.006192010000093506,
|
||||
0.013986702816730645,
|
||||
0.025003956956430873,
|
||||
0.03935464078941209,
|
||||
0.057190958417936644,
|
||||
0.07871533601238889,
|
||||
0.10419358352238339,
|
||||
0.1339745962155614,
|
||||
0.1685205807169019,
|
||||
0.20845517506805522,
|
||||
0.2546440075000701,
|
||||
0.3083389112228482,
|
||||
0.37146063894529113,
|
||||
0.4472292016074334,
|
||||
0.5418771527091488,
|
||||
0.6713289009389102,
|
||||
1,
|
||||
],
|
||||
out_circle: [
|
||||
0,
|
||||
0.3286710990610898,
|
||||
0.45812284729085123,
|
||||
0.5527707983925666,
|
||||
0.6285393610547089,
|
||||
0.6916610887771518,
|
||||
0.7453559924999298,
|
||||
0.7915448249319448,
|
||||
0.8314794192830981,
|
||||
0.8660254037844386,
|
||||
0.8958064164776166,
|
||||
0.9212846639876111,
|
||||
0.9428090415820634,
|
||||
0.9606453592105879,
|
||||
0.9749960430435691,
|
||||
0.9860132971832694,
|
||||
0.9938079899999065,
|
||||
0.9984555975339683,
|
||||
1,
|
||||
],
|
||||
inOut_circle: [
|
||||
0,
|
||||
0.003096005000046753,
|
||||
0.012501978478215436,
|
||||
0.028595479208968322,
|
||||
0.052096791761191696,
|
||||
0.08426029035845095,
|
||||
0.12732200375003505,
|
||||
0.18573031947264557,
|
||||
0.2709385763545744,
|
||||
0.5,
|
||||
0.7290614236454256,
|
||||
0.8142696805273546,
|
||||
0.8726779962499649,
|
||||
0.915739709641549,
|
||||
0.9479032082388084,
|
||||
0.9714045207910317,
|
||||
0.9874980215217846,
|
||||
0.9969039949999532,
|
||||
1,
|
||||
],
|
||||
in_back_: [
|
||||
0,
|
||||
-0.004788556241426612,
|
||||
-0.017301289437585736,
|
||||
-0.0347587962962963,
|
||||
-0.05438167352537723,
|
||||
-0.07339051783264748,
|
||||
-0.08900592592592595,
|
||||
-0.09844849451303156,
|
||||
-0.0989388203017833,
|
||||
-0.08769750000000004,
|
||||
-0.06194513031550073,
|
||||
-0.018902307956104283,
|
||||
0.044210370370370254,
|
||||
0.13017230795610413,
|
||||
0.2417629080932785,
|
||||
0.3817615740740742,
|
||||
0.5529477091906719,
|
||||
0.7581007167352535,
|
||||
0.9999999999999998,
|
||||
],
|
||||
out_back_: [
|
||||
2.220446049250313e-16,
|
||||
0.24189928326474652,
|
||||
0.44705229080932807,
|
||||
0.6182384259259258,
|
||||
0.7582370919067215,
|
||||
0.8698276920438959,
|
||||
0.9557896296296297,
|
||||
1.0189023079561044,
|
||||
1.0619451303155008,
|
||||
1.0876975,
|
||||
1.0989388203017834,
|
||||
1.0984484945130315,
|
||||
1.089005925925926,
|
||||
1.0733905178326475,
|
||||
1.0543816735253773,
|
||||
1.0347587962962963,
|
||||
1.0173012894375857,
|
||||
1.0047885562414267,
|
||||
1,
|
||||
],
|
||||
};
|
||||
|
||||
Object.keys(Samples).forEach(function(type) {
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
|
||||
|
||||
@@ -74,7 +74,10 @@ describe('bezier', function() {
|
||||
describe('common properties', function() {
|
||||
it('should be the right value at extremes', function() {
|
||||
repeat(10)(function() {
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5;
|
||||
const a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = Math.random(),
|
||||
d = 2 * Math.random() - 0.5;
|
||||
const easing = bezier(a, b, c, d);
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(1)).toBe(1);
|
||||
@@ -83,7 +86,10 @@ describe('bezier', function() {
|
||||
|
||||
it('should approach the projected value of its x=y projected curve', function() {
|
||||
repeat(10)(function() {
|
||||
const a = Math.random(), b = Math.random(), c = Math.random(), d = Math.random();
|
||||
const a = Math.random(),
|
||||
b = Math.random(),
|
||||
c = Math.random(),
|
||||
d = Math.random();
|
||||
const easing = bezier(a, b, c, d);
|
||||
const projected = bezier(b, a, d, c);
|
||||
const composed = function(x) {
|
||||
@@ -96,7 +102,10 @@ describe('bezier', function() {
|
||||
describe('two same instances', function() {
|
||||
it('should be strictly equals', function() {
|
||||
repeat(10)(function() {
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5;
|
||||
const a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = Math.random(),
|
||||
d = 2 * Math.random() - 0.5;
|
||||
allEquals(bezier(a, b, c, d), bezier(a, b, c, d), 100, 0);
|
||||
});
|
||||
});
|
||||
@@ -104,14 +113,20 @@ describe('bezier', function() {
|
||||
describe('symetric curves', function() {
|
||||
it('should have a central value y~=0.5 at x=0.5', function() {
|
||||
repeat(10)(function() {
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b;
|
||||
const a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = 1 - a,
|
||||
d = 1 - b;
|
||||
const easing = bezier(a, b, c, d);
|
||||
assertClose(easing(0.5), 0.5, 2);
|
||||
});
|
||||
});
|
||||
it('should be symmetrical', function() {
|
||||
repeat(10)(function() {
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b;
|
||||
const a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = 1 - a,
|
||||
d = 1 - b;
|
||||
const easing = bezier(a, b, c, d);
|
||||
const sym = function(x) {
|
||||
return 1 - easing(1 - x);
|
||||
|
||||
@@ -2,47 +2,64 @@
|
||||
* BezierEasing - use bezier curve for transition easing function
|
||||
* https://github.com/gre/bezier-easing
|
||||
*
|
||||
* @format
|
||||
* @copyright 2014-2015 Gaëtan Renaudeau. MIT License.
|
||||
* @noflow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// These values are established by empiricism with tests (tradeoff: performance VS precision)
|
||||
const NEWTON_ITERATIONS = 4;
|
||||
const NEWTON_MIN_SLOPE = 0.001;
|
||||
const SUBDIVISION_PRECISION = 0.0000001;
|
||||
const SUBDIVISION_MAX_ITERATIONS = 10;
|
||||
// These values are established by empiricism with tests (tradeoff: performance VS precision)
|
||||
const NEWTON_ITERATIONS = 4;
|
||||
const NEWTON_MIN_SLOPE = 0.001;
|
||||
const SUBDIVISION_PRECISION = 0.0000001;
|
||||
const SUBDIVISION_MAX_ITERATIONS = 10;
|
||||
|
||||
const kSplineTableSize = 11;
|
||||
const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
||||
const kSplineTableSize = 11;
|
||||
const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
||||
|
||||
const float32ArraySupported = typeof Float32Array === 'function';
|
||||
const float32ArraySupported = typeof Float32Array === 'function';
|
||||
|
||||
function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
|
||||
function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
|
||||
function C (aA1) { return 3.0 * aA1; }
|
||||
function A(aA1, aA2) {
|
||||
return 1.0 - 3.0 * aA2 + 3.0 * aA1;
|
||||
}
|
||||
function B(aA1, aA2) {
|
||||
return 3.0 * aA2 - 6.0 * aA1;
|
||||
}
|
||||
function C(aA1) {
|
||||
return 3.0 * aA1;
|
||||
}
|
||||
|
||||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
||||
function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; }
|
||||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
||||
function calcBezier(aT, aA1, aA2) {
|
||||
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
|
||||
}
|
||||
|
||||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
|
||||
function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); }
|
||||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
|
||||
function getSlope(aT, aA1, aA2) {
|
||||
return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
|
||||
}
|
||||
|
||||
function binarySubdivide (aX, aA, aB, mX1, mX2) {
|
||||
let currentX, currentT, i = 0;
|
||||
do {
|
||||
currentT = aA + (aB - aA) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
||||
if (currentX > 0.0) {
|
||||
aB = currentT;
|
||||
} else {
|
||||
aA = currentT;
|
||||
}
|
||||
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
|
||||
return currentT;
|
||||
}
|
||||
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
||||
let currentX,
|
||||
currentT,
|
||||
i = 0;
|
||||
do {
|
||||
currentT = aA + (aB - aA) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
||||
if (currentX > 0.0) {
|
||||
aB = currentT;
|
||||
} else {
|
||||
aA = currentT;
|
||||
}
|
||||
} while (
|
||||
Math.abs(currentX) > SUBDIVISION_PRECISION &&
|
||||
++i < SUBDIVISION_MAX_ITERATIONS
|
||||
);
|
||||
return currentT;
|
||||
}
|
||||
|
||||
function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
|
||||
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
||||
for (let i = 0; i < NEWTON_ITERATIONS; ++i) {
|
||||
const currentSlope = getSlope(aGuessT, mX1, mX2);
|
||||
if (currentSlope === 0.0) {
|
||||
@@ -52,56 +69,71 @@
|
||||
aGuessT -= currentX / currentSlope;
|
||||
}
|
||||
return aGuessT;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function bezier (mX1, mY1, mX2, mY2) {
|
||||
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { // eslint-disable-line yoda
|
||||
throw new Error('bezier x values must be in [0, 1] range');
|
||||
}
|
||||
module.exports = function bezier(mX1, mY1, mX2, mY2) {
|
||||
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
|
||||
// eslint-disable-line yoda
|
||||
throw new Error('bezier x values must be in [0, 1] range');
|
||||
}
|
||||
|
||||
// Precompute samples table
|
||||
const sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
|
||||
if (mX1 !== mY1 || mX2 !== mY2) {
|
||||
for (let i = 0; i < kSplineTableSize; ++i) {
|
||||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
||||
}
|
||||
}
|
||||
// Precompute samples table
|
||||
const sampleValues = float32ArraySupported
|
||||
? new Float32Array(kSplineTableSize)
|
||||
: new Array(kSplineTableSize);
|
||||
if (mX1 !== mY1 || mX2 !== mY2) {
|
||||
for (let i = 0; i < kSplineTableSize; ++i) {
|
||||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
||||
}
|
||||
}
|
||||
|
||||
function getTForX (aX) {
|
||||
let intervalStart = 0.0;
|
||||
let currentSample = 1;
|
||||
const lastSample = kSplineTableSize - 1;
|
||||
function getTForX(aX) {
|
||||
let intervalStart = 0.0;
|
||||
let currentSample = 1;
|
||||
const lastSample = kSplineTableSize - 1;
|
||||
|
||||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
|
||||
intervalStart += kSampleStepSize;
|
||||
}
|
||||
--currentSample;
|
||||
for (
|
||||
;
|
||||
currentSample !== lastSample && sampleValues[currentSample] <= aX;
|
||||
++currentSample
|
||||
) {
|
||||
intervalStart += kSampleStepSize;
|
||||
}
|
||||
--currentSample;
|
||||
|
||||
// Interpolate to provide an initial guess for t
|
||||
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
||||
const guessForT = intervalStart + dist * kSampleStepSize;
|
||||
// Interpolate to provide an initial guess for t
|
||||
const dist =
|
||||
(aX - sampleValues[currentSample]) /
|
||||
(sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
||||
const guessForT = intervalStart + dist * kSampleStepSize;
|
||||
|
||||
const initialSlope = getSlope(guessForT, mX1, mX2);
|
||||
if (initialSlope >= NEWTON_MIN_SLOPE) {
|
||||
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
||||
} else if (initialSlope === 0.0) {
|
||||
return guessForT;
|
||||
} else {
|
||||
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
||||
}
|
||||
}
|
||||
const initialSlope = getSlope(guessForT, mX1, mX2);
|
||||
if (initialSlope >= NEWTON_MIN_SLOPE) {
|
||||
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
||||
} else if (initialSlope === 0.0) {
|
||||
return guessForT;
|
||||
} else {
|
||||
return binarySubdivide(
|
||||
aX,
|
||||
intervalStart,
|
||||
intervalStart + kSampleStepSize,
|
||||
mX1,
|
||||
mX2,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return function BezierEasing (x) {
|
||||
if (mX1 === mY1 && mX2 === mY2) {
|
||||
return x; // linear
|
||||
}
|
||||
// Because JavaScript number are imprecise, we should guarantee the extremes are right.
|
||||
if (x === 0) {
|
||||
return 0;
|
||||
}
|
||||
if (x === 1) {
|
||||
return 1;
|
||||
}
|
||||
return calcBezier(getTForX(x), mY1, mY2);
|
||||
};
|
||||
};
|
||||
return function BezierEasing(x) {
|
||||
if (mX1 === mY1 && mX2 === mY2) {
|
||||
return x; // linear
|
||||
}
|
||||
// Because JavaScript number are imprecise, we should guarantee the extremes are right.
|
||||
if (x === 0) {
|
||||
return 0;
|
||||
}
|
||||
if (x === 1) {
|
||||
return 1;
|
||||
}
|
||||
return calcBezier(getTForX(x), mY1, mY2);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
createInteractionHandle: function() {},
|
||||
clearInteractionHandle: function() {}
|
||||
clearInteractionHandle: function() {},
|
||||
};
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
module.exports = function(style) {
|
||||
return style;
|
||||
|
||||
Reference in New Issue
Block a user