Skip to content

Instantly share code, notes, and snippets.

@bowd
Forked from valer-cara/index.jsx
Last active August 29, 2015 14:17
Show Gist options
  • Save bowd/4c81d7f78372a4a71ac4 to your computer and use it in GitHub Desktop.
Save bowd/4c81d7f78372a4a71ac4 to your computer and use it in GitHub Desktop.
initiateTransition: function() {
// Set the state so that both screens
// will be rendered.
this.setState({
transitionStarted: true,
transitionDirection: this.state.activeScreen.get('stackIndex') > this.state.screensStackTop.get('stackIndex') ? "back" : "fwd"
});
// Schedule a cleanup so that we remove the
// previous screen after the transition occurs
setTimeout(function() {
// VALI HINT 1: Maybe we can change the name of this
_this._resetTransition();
}, 1000);
// VALI HINT 2: What if we keep the time as a local constant
// ANIMATION_DURATION, and what if we dynamically set
// the 'animation-duration' style from js based on that
// constant?
},
shouldTransition: function() {
return !this.state.transitionStarted &&
!this._equalScreens(this.state.activeScreen, this.state.screensStackTop);
},
shouldStartAnimation: function() {
return this.state.transitionStarted && !this.state.isTransitioning;
},
componentDidUpdate: function(prevProps, prevState) {
var _this = this;
if (this.shouldTransition()) {
this.initiateTransition();
} else if (this.shouldStartAnimation()) {
this.setState({ isTransitioning: true });
}
},
@valer-cara
Copy link

@bogdan-dumitru i'm very pleased! 💌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment