Skip to content

Commit

Permalink
Add onStart callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Wang Zhongliang committed Jun 19, 2018
1 parent 5eeedf3 commit 7f4f854
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Spring extends React.PureComponent {
from: PropTypes.object,
// Animates to ...
to: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
// Callback when the animation starts to animate
onStart: PropTypes.func,
// Callback when the animation comes to a still-stand
onRest: PropTypes.func,
// Frame by frame callback, first argument passed is the animated value
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ declare module 'react-spring' {
* @default {}
*/
to: DS;
/**
* Callback when the animation starts to animate
*/
onStart?: () => void;
/**
* Callback when the animation comes to a still-stand
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class Spring extends React.Component {
to: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
from: PropTypes.object,
native: PropTypes.bool,
onStart: PropTypes.func,
onRest: PropTypes.func,
onFrame: PropTypes.func,
children: PropTypes.oneOfType([
Expand Down Expand Up @@ -97,6 +98,7 @@ export default class Spring extends React.Component {
immediate,
reset,
onFrame,
onStart,
onRest,
inject,
native,
Expand Down Expand Up @@ -172,6 +174,7 @@ export default class Spring extends React.Component {

entry.start = cb => {
if (entry.animation.__getValue() === toValue) return entry.onFinish(cb)
if (onStart) onStart()
controller(
entry.animation,
{ to: toValue, ...callProp(config, name) },
Expand Down

0 comments on commit 7f4f854

Please sign in to comment.