{"_id":"kw-react-tween-state","_rev":"2858683","name":"kw-react-tween-state","description":"React animation.","dist-tags":{"latest":"0.1.5"},"maintainers":[{"name":"thekenwheeler","email":"ken@outlook.com"}],"time":{"modified":"2022-09-06T17:11:50.000Z","created":"2016-04-19T09:57:03.179Z","0.1.5":"2016-04-19T09:57:03.179Z"},"users":{},"author":{"name":"Cheng Lou"},"repository":{"type":"git","url":"git+https://github.com/chenglou/react-tween-state.git"},"versions":{"0.1.5":{"name":"kw-react-tween-state","version":"0.1.5","description":"React animation.","main":"lib/index.js","directories":{"examples":"examples"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"webpack -p","start":"webpack -w -d"},"repository":{"type":"git","url":"git+https://github.com/chenglou/react-tween-state.git"},"keywords":["react","animation","tween","transition","state","interactive","mixin","interpolation"],"author":{"name":"Cheng Lou"},"license":"BSD","bugs":{"url":"https://github.com/chenglou/react-tween-state/issues"},"homepage":"https://github.com/chenglou/react-tween-state","devDependencies":{"babel-core":"^5.6.1","babel-loader":"^5.1.4","node-libs-browser":"^0.5.2","webpack":"^1.9.11"},"peerDependencies":{"react":"^0.14.8 || ^15.0.1","react-dom":"^0.14.8 || ^15.0.1"},"dependencies":{"raf":"^3.1.0","tween-functions":"^1.0.1"},"gitHead":"49e12eefab3616664d93f2ac06349bf65a70c652","_id":"kw-react-tween-state@0.1.5","_shasum":"744088988d35f14ccc2ca36af96bc09ece7ab78b","_from":".","_npmVersion":"3.6.0","_nodeVersion":"5.4.0","_npmUser":{"name":"thekenwheeler","email":"ken_wheeler@me.com"},"dist":{"shasum":"744088988d35f14ccc2ca36af96bc09ece7ab78b","size":12790,"noattachment":false,"key":"/kw-react-tween-state/-/kw-react-tween-state-0.1.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/kw-react-tween-state/download/kw-react-tween-state-0.1.5.tgz"},"maintainers":[{"name":"thekenwheeler","email":"ken@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/kw-react-tween-state-0.1.5.tgz_1461059820660_0.827548551838845"},"publish_time":1461059823179,"_hasShrinkwrap":false,"_cnpm_publish_time":1461059823179,"_cnpmcore_publish_time":"2021-12-16T15:10:03.089Z"}},"readme":"# [React](http://facebook.github.io/react/) Tween State\n\nThe equivalent of React's `this.setState`, but for animated tweens: `this.tweenState`.\n\n[Live demo](https://rawgit.com/chenglou/react-tween-state/master/examples/index.html) and [source](https://github.com/chenglou/react-tween-state/tree/master/examples).\n\nNpm:\n```sh\nnpm install react-tween-state\n```\n\nBower:\n```sh\nbower install react-tween-state\n```\n\n## API\n\nExample usage:\n\n```js\nvar tweenState = require('react-tween-state');\nvar React = require('react');\n\nvar App = React.createClass({\n  mixins: [tweenState.Mixin],\n  getInitialState: function() {\n    return {left: 0};\n  },\n  handleClick: function() {\n    this.tweenState('left', {\n      easing: tweenState.easingTypes.easeInOutQuad,\n      duration: 500,\n      endValue: this.state.left === 0 ? 400 : 0\n    });\n  },\n  render: function() {\n    var style = {\n      position: 'absolute',\n      width: 50,\n      height: 50,\n      backgroundColor: 'lightblue',\n      left: this.getTweeningValue('left')\n    };\n    return <div style={style} onClick={this.handleClick} />;\n  }\n});\n```\n\nThe library exports `Mixin`, `easingTypes` and `stackBehavior`.\n\n#### `this.tweenState(path: String | Array<String>, configuration: Object)`\n\nThis first calls `setState` **and puts your fields straight to their final value**. Under the hood, it creates a layer that interpolates from the old value to the new. You can retrieve that tweening value using `getTweeningValue` below.\n\n`path` is the name of the state field you want to tween. If it's deeply nested, e.g. to animate `c` in {a: {b: {c: 1}}}, provide the path as `['a', 'b', 'c']`\n\n`configuration` is of the following format:\n\n```js\n{\n  easing: easingFunction,\n  duration: timeInMilliseconds,\n  delay: timeInMilliseconds,\n  beginValue: aNumber,\n  endValue: aNumber,\n  onEnd: endCallback,\n  stackBehavior: behaviorOption\n}\n```\n\n  - `easing` (default: `easingTypes.easeInOutQuad`): the interpolation function used. react-tween-state provides [frequently used interpolation](https://github.com/chenglou/tween-functions/blob/master/index.js) (exposed under `easingTypes`). To plug in your own, the function signature is: `(currentTime: Number, beginValue: Number, endValue: Number, totalDuration: Number): Number`.\n  - `duration` (default: `300`).\n  - `delay` (default: `0`). *\n  - `beginValue` (default: the current value of the state field).\n  - `endValue`.\n  - `onEnd`: the callback to trigger when the animation's done. **\n  - `stackBehavior` (default: `stackBehavior.ADDITIVE`). Subsequent tween to the same state value will be stacked (added together). This gives a smooth tween effect that is iOS 8's new default. [This blog post](http://ronnqvi.st/multiple-animations/) describes it well. The other option is `stackBehavior.DESTRUCTIVE`, which replaces all current animations of that state value by this new one.\n\n\\* For a destructive animation, starting the next one with a delay still immediately kills the previous tween. If that's not your intention, try `setTimeout` or additive animation. `DESTRUCTIVE` + `duration` 0 effectively cancels all in-flight animations, **skipping the easing function**.\n\n\\*\\* For an additive animation, since the tweens stack and never get destroyed, the end callback is effectively fired at the end of `duration`.\n\n#### `this.getTweeningValue(path: String | Array<String>)`\nGet the current tweening value of the state field. Typically used in `render`.\n\n## License\nBSD.\n","_attachments":{},"homepage":"https://github.com/chenglou/react-tween-state","bugs":{"url":"https://github.com/chenglou/react-tween-state/issues"},"license":"BSD"}