Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-motion

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-motion - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

lib/components.js

4

HISTORY.md

@@ -7,2 +7,6 @@ Legend:

### 0.2.5 (July 31th 2015)
- [F] React-native warning's now gone, but also put into a separate file path. To require react-motion on react-native, do `require('react-motion/native')`.
- [I] Support for React 0.14.0-beta1.
### 0.2.4 (July 29th 2015)

@@ -9,0 +13,0 @@ - [I] React-native support!

284

lib/Spring.js
'use strict';
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _mapTree = require('./mapTree');
var _react = require('react');
var _mapTree2 = _interopRequireDefault(_mapTree);
var _react2 = _interopRequireDefault(_react);
var _noVelocity = require('./noVelocity');
var _components = require('./components');
var _noVelocity2 = _interopRequireDefault(_noVelocity);
var _components2 = _interopRequireDefault(_components);
var _compareTrees = require('./compareTrees');
var _compareTrees2 = _interopRequireDefault(_compareTrees);
var _mergeDiff = require('./mergeDiff');
var _mergeDiff2 = _interopRequireDefault(_mergeDiff);
var _animationLoop = require('./animationLoop');
var _animationLoop2 = _interopRequireDefault(_animationLoop);
var _zero = require('./zero');
var _zero2 = _interopRequireDefault(_zero);
var _updateTree = require('./updateTree');
var React = undefined;
try {
React = require('react-native');
} catch (e) {
React = require('react');
}
var _React = React;
var PropTypes = _React.PropTypes;
var startAnimation = _animationLoop2['default']();
function animationStep(shouldMerge, stopAnimation, getProps, timestep, state) {
var currValue = state.currValue;
var currVelocity = state.currVelocity;
var _getProps = getProps();
var willEnter = _getProps.willEnter;
var willLeave = _getProps.willLeave;
var endValue = _getProps.endValue;
if (typeof endValue === 'function') {
endValue = endValue(currValue);
}
var mergedValue = endValue; // set mergedValue to endValue as the default
var hasNewKey = false;
if (shouldMerge) {
mergedValue = _mergeDiff2['default'](currValue, endValue,
// TODO: stop allocating like crazy in this whole code path
function (key) {
var res = willLeave(key, currValue[key], endValue, currValue, currVelocity);
if (res == null) {
// For legacy reason. We won't allow returning null soon
// TODO: remove, after next release
return null;
}
if (_noVelocity2['default'](currVelocity[key]) && _compareTrees2['default'](currValue[key], res)) {
return null;
}
return res;
});
Object.keys(mergedValue).filter(function (key) {
return !currValue.hasOwnProperty(key);
}).forEach(function (key) {
hasNewKey = true;
var enterValue = willEnter(key, mergedValue[key], endValue, currValue, currVelocity);
currValue[key] = enterValue;
mergedValue[key] = enterValue;
currVelocity[key] = _mapTree2['default'](_zero2['default'], currValue[key]);
});
}
var newCurrValue = _updateTree.updateCurrValue(timestep, currValue, currVelocity, mergedValue);
var newCurrVelocity = _updateTree.updateCurrVelocity(timestep, currValue, currVelocity, mergedValue);
if (!hasNewKey && _noVelocity2['default'](currVelocity) && _noVelocity2['default'](newCurrVelocity)) {
// check explanation in `Spring.animationRender`
stopAnimation(); // Nasty side effects....
}
return {
currValue: newCurrValue,
currVelocity: newCurrVelocity
};
}
var Spring = React.createClass({
displayName: 'Spring',
propTypes: {
defaultValue: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
endValue: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.array]).isRequired,
children: PropTypes.func.isRequired
},
getInitialState: function getInitialState() {
var _props = this.props;
var endValue = _props.endValue;
var defaultValue = _props.defaultValue;
var currValue = undefined;
if (defaultValue == null) {
if (typeof endValue === 'function') {
// TODO: provide perf tip here when endValue argument count is 0
// (meaning you could have passed an obj)
currValue = endValue();
} else {
currValue = endValue;
}
} else {
currValue = defaultValue;
}
return {
currValue: currValue,
currVelocity: _mapTree2['default'](_zero2['default'], currValue)
};
},
componentDidMount: function componentDidMount() {
var _this = this;
this.animationStep = animationStep.bind(null, false, function () {
return _this.stopAnimation();
}, function () {
return _this.props;
});
this.startAnimating();
},
componentWillReceiveProps: function componentWillReceiveProps() {
this.startAnimating();
},
stopAnimation: null,
// used in animationRender
hasUnmounted: false,
animationStep: null,
componentWillUnmount: function componentWillUnmount() {
this.stopAnimation();
this.hasUnmounted = true;
},
startAnimating: function startAnimating() {
// Is smart enough to not start it twice
this.stopAnimation = startAnimation(this.state, this.animationStep, this.animationRender);
},
animationRender: function animationRender(alpha, nextState, prevState) {
// `this.hasUnmounted` might be true in the following condition:
// user does some checks in `endValue` and calls an owner handler
// owner sets state in the callback, triggering a re-render
// re-render unmounts the Spring
if (!this.hasUnmounted) {
this.setState({
currValue: _updateTree.interpolateValue(alpha, nextState.currValue, prevState.currValue),
currVelocity: nextState.currVelocity
});
}
},
render: function render() {
var renderedChildren = this.props.children(this.state.currValue);
return renderedChildren && React.Children.only(renderedChildren);
}
});
exports.Spring = Spring;
var TransitionSpring = React.createClass({
displayName: 'TransitionSpring',
propTypes: {
defaultValue: PropTypes.objectOf(PropTypes.any),
endValue: PropTypes.oneOfType([PropTypes.func, PropTypes.objectOf(PropTypes.any.isRequired)]).
// PropTypes.arrayOf(PropTypes.shape({
// key: PropTypes.any.isRequired,
// })),
// PropTypes.arrayOf(PropTypes.element),
isRequired,
willLeave: PropTypes.oneOfType([PropTypes.func]),
// PropTypes.object,
// PropTypes.array,
willEnter: PropTypes.oneOfType([PropTypes.func]),
// PropTypes.object,
// PropTypes.array,
children: PropTypes.func.isRequired
},
getDefaultProps: function getDefaultProps() {
return {
willEnter: function willEnter(key, value) {
return value;
},
willLeave: function willLeave() {
return null;
}
};
},
getInitialState: function getInitialState() {
var _props2 = this.props;
var endValue = _props2.endValue;
var defaultValue = _props2.defaultValue;
var currValue = undefined;
if (defaultValue == null) {
if (typeof endValue === 'function') {
currValue = endValue();
} else {
currValue = endValue;
}
} else {
currValue = defaultValue;
}
return {
currValue: currValue,
currVelocity: _mapTree2['default'](_zero2['default'], currValue)
};
},
componentDidMount: function componentDidMount() {
var _this2 = this;
this.animationStep = animationStep.bind(null, true, function () {
return _this2.stopAnimation();
}, function () {
return _this2.props;
});
this.startAnimating();
},
componentWillReceiveProps: function componentWillReceiveProps() {
this.startAnimating();
},
stopAnimation: null,
// used in animationRender
hasUnmounted: false,
animationStep: null,
componentWillUnmount: function componentWillUnmount() {
this.stopAnimation();
},
startAnimating: function startAnimating() {
this.stopAnimation = startAnimation(this.state, this.animationStep, this.animationRender);
},
animationRender: function animationRender(alpha, nextState, prevState) {
// See comment in Spring.
if (!this.hasUnmounted) {
this.setState({
currValue: _updateTree.interpolateValue(alpha, nextState.currValue, prevState.currValue),
currVelocity: nextState.currVelocity
});
}
},
render: function render() {
var renderedChildren = this.props.children(this.state.currValue);
return renderedChildren && React.Children.only(renderedChildren);
}
});
exports.TransitionSpring = TransitionSpring;
module.exports = _components2['default'](_react2['default']);
{
"name": "react-motion",
"version": "0.2.4",
"version": "0.2.5",
"description": "A spring that solves your animation problems.",
"main": "lib/react-motion.js",
"peerDependencies": {
"react": ">=0.13.2"
"react": ">=0.13.2 || 0.14.0-beta1"
},
"devDependencies": {
"babel": "^5.6.14",
"babel-browser-transform": "^0.1.0",
"babel-core": "^5.6.18",
"babel-eslint": "^3.1.23",
"babel-loader": "^5.3.1",
"codemirror": "^5.5.0",
"eslint": "^0.24.1",

@@ -28,2 +30,3 @@ "eslint-config-airbnb": "0.0.6",

"phantomjs": "^1.9.17",
"react-codemirror": "^0.1.2",
"react-hot-loader": "^1.2.8",

@@ -30,0 +33,0 @@ "webpack": "^1.10.1",

@@ -27,4 +27,6 @@ # React-Motion

[Check](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo0/index.html) [Out](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo1/index.html) [The](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo2/index.html) [Cool](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo3/index.html) [Demos](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo4/index.html) [Here](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo5/index.html).
**For React-native**, instead of `require('react-motion')`, do `require('react-motion/native')`.
[Check](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo0/index.html) [Out](https://cdn.rawgit.com/chenglou/react-motion/6d4379f7d3a4677f298c64f85794b422a53c916c/demos/demo1/index.html) [The](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo2/index.html) [Cool](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo3/index.html) [Demos](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo4/index.html) [Here](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo5/index.html).
## What does this library try to solve?

@@ -299,3 +301,3 @@

- How do I do staggering/chained animation where items animate in one after another?
In most cases, what you want to express here is a relationship between animations, e.g. item 2 appears after item 1. Staggering/chained animation have hard-coded values and go against the spirit of a physics system. Check out [demo 1](https://cdn.rawgit.com/chenglou/react-motion/c3c5403b6821b7a8954e3c379057ae7d9bbc39d5/demos/demo1/index.html); each ball follows the one in front of it, creating a natural staggering animation. The code in `endValue` looks roughly so:
In most cases, what you want to express here is a relationship between animations, e.g. item 2 appears after item 1. Staggering/chained animation have hard-coded values and go against the spirit of a physics system. Check out [demo 1](https://cdn.rawgit.com/chenglou/react-motion/6d4379f7d3a4677f298c64f85794b422a53c916c/demos/demo1/index.html); each ball follows the one in front of it, creating a natural staggering animation. The code in `endValue` looks roughly so:

@@ -302,0 +304,0 @@ ```jsx

@@ -34,4 +34,3 @@ var webpack = require('webpack');

amd: 'react'
},
'react-native': true,
}
},

@@ -38,0 +37,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc