@@ -7,6 +7,12 @@ import AnimatedProps from './animated/AnimatedProps'
77import SpringAnimation from './animated/SpringAnimation'
88import * as Globals from './animated/Globals'
99
10+ function shallowDiff ( a , b ) {
11+ for ( let i in a ) if ( ! ( i in b ) ) return true
12+ for ( let i in b ) if ( a [ i ] !== b [ i ] ) return true
13+ return false
14+ }
15+
1016export const config = {
1117 default : { tension : 170 , friction : 26 } ,
1218 gentle : { tension : 120 , friction : 14 } ,
@@ -21,7 +27,7 @@ const convert = (acc, [name, value]) => ({
2127 [ name ] : new AnimatedValue ( value ) ,
2228} )
2329
24- export default class Spring extends React . PureComponent {
30+ export default class Spring extends React . Component {
2531 static propTypes = {
2632 to : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func ] ) ,
2733 from : PropTypes . object ,
@@ -37,7 +43,6 @@ export default class Spring extends React.PureComponent {
3743 reset : PropTypes . bool ,
3844 config : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func ] ) ,
3945 immediate : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
40- hold : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
4146 impl : PropTypes . func ,
4247 inject : PropTypes . func ,
4348 }
@@ -48,7 +53,6 @@ export default class Spring extends React.PureComponent {
4853 config : config . default ,
4954 native : false ,
5055 immediate : false ,
51- hold : false ,
5256 reset : false ,
5357 impl : SpringAnimation ,
5458 inject : Globals . bugfixes ,
@@ -65,8 +69,9 @@ export default class Spring extends React.PureComponent {
6569 this . updatePropsAsync ( this . props )
6670 }
6771
68- componentWillReceiveProps ( props ) {
69- this . updatePropsAsync ( props )
72+ componentWillUpdate ( props ) {
73+ if ( props . reset || shallowDiff ( props . to , this . props . to ) )
74+ this . updatePropsAsync ( props )
7075 }
7176
7277 updatePropsAsync ( props ) {
@@ -90,7 +95,6 @@ export default class Spring extends React.PureComponent {
9095 config,
9196 attach,
9297 immediate,
93- hold,
9498 reset,
9599 onFrame,
96100 onRest,
@@ -149,11 +153,12 @@ export default class Spring extends React.PureComponent {
149153 if ( callProp ( immediate , name ) ) entry . animation . setValue ( toValue )
150154
151155 entry . stopped = false
156+
152157 entry . onFinish = cb => {
153158 this . animations [ name ] . stopped = true
154159 if ( this . getAnimations ( ) . every ( a => a . stopped ) ) {
155160 const current = { ...this . props . from , ...this . props . to }
156- onRest && onRest ( current )
161+ if ( onRest ) onRest ( current )
157162 cb && typeof cb === 'function' && cb ( current )
158163
159164 if ( didInject ) {
@@ -164,16 +169,16 @@ export default class Spring extends React.PureComponent {
164169 }
165170 }
166171 }
167- entry . start = cb => {
168- // Skip held animations
169- if ( callProp ( hold , name ) ) return entry . onFinish ( cb )
170172
173+ entry . start = cb => {
174+ if ( entry . animation . __getValue ( ) === toValue ) return
171175 controller (
172176 entry . animation ,
173177 { to : toValue , ...callProp ( config , name ) } ,
174178 impl
175179 ) . start ( props => props . finished && entry . onFinish ( cb ) )
176180 }
181+
177182 entry . stop = ( ) => {
178183 entry . stopped = true
179184 entry . animation . stopAnimation ( )
@@ -256,7 +261,6 @@ export default class Spring extends React.PureComponent {
256261 immediate,
257262 impl,
258263 inject,
259- hold,
260264 ...forward
261265 } = props
262266 return forward
0 commit comments