{"id":13437340,"url":"https://github.com/chenglou/react-tween-state","last_synced_at":"2025-05-14T18:06:18.701Z","repository":{"id":18484074,"uuid":"21679551","full_name":"chenglou/react-tween-state","owner":"chenglou","description":"React animation.","archived":false,"fork":false,"pushed_at":"2017-09-12T19:56:54.000Z","size":1433,"stargazers_count":1738,"open_issues_count":9,"forks_count":70,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-05-06T05:02:59.599Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenglou.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-10T04:43:35.000Z","updated_at":"2025-04-08T13:31:25.000Z","dependencies_parsed_at":"2022-09-11T20:31:05.923Z","dependency_job_id":null,"html_url":"https://github.com/chenglou/react-tween-state","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-tween-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-tween-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-tween-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-tween-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenglou","download_url":"https://codeload.github.com/chenglou/react-tween-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253584492,"owners_count":21931547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:00:56.108Z","updated_at":"2025-05-14T18:06:13.693Z","avatar_url":"https://github.com/chenglou.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized","Awesome React","UI Animation","Ferramentas","JavaScript"],"sub_categories":["Uncategorized","Tools","Form Components"],"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 \u003cdiv style={style} onClick={this.handleClick} /\u003e;\n  }\n});\n```\n\nThe library exports `Mixin`, `easingTypes` and `stackBehavior`.\n\n#### `this.tweenState(path: String | Array\u003cString\u003e, 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\u003cString\u003e)`\nGet the current tweening value of the state field. Typically used in `render`.\n\n## License\nBSD.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenglou%2Freact-tween-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenglou%2Freact-tween-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenglou%2Freact-tween-state/lists"}