-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Because state changes in React components can be asynchronous, the plugin has to track a proxy for the component state so that multiple tweens can act in between component updates.
But, because the component doesn't know about this proxy, there is no way for the tweens to know when the state is changed outside of the tweening process. For example:
React.createClass({
getInitialState: function() {
return {x: 0}
},
componentDidMount: function() {
// Tween state.x from the initial value of 0 to 100.
// When that tween completes, set the state back to 0.
TweenLite
.to(this, 0.5, {state: {x: 100}})
.addCallback('onComplete', function(){
this.setState({x: 0});
}.bind(this));
},
componentDidUpdate: function() {
// You would expect this to tween to 100 starting from 0, since the state
// was updated in the 'onComplete' callback in `componentDidMount`, but it
// doesn't because the internal plugin proxy doesn't know the state changed!
TweenLite
.to(this, 0.5, {state: {x: 100}});
},
render: function() { /* etc... */ }
});There doesn't seem to be any good options for solving this.
Here are some bad ones:
- mutate
target.statedirectly (instead of maintaining an separate tween state and binding them together)- bad because it will cause issues for
componentShouldUpdateandcomponentDidUpdate, when comparisons between previous and next tween states are inaccurate (since the state gets mutated directly between renders by the tween)
- bad because it will cause issues for
- override
target.setStateto make sure it also updates the tween state- this just seems evil
- add a
setTweenStatemethod to the component that can update the tween proxy object and callsetState- this means your component has to use this special method everywhere that it would normally use
setState(or at least everywhere that the component would want to update state that is also being tweened) - might be the best option?
- this means your component has to use this special method everywhere that it would normally use
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels