I'v tried to use react-router and ReactTransitionGroup to make an navigation effect(page slide whereas route changes).
However, it's error-prone and ugly.(made much logic to define which direction to slide to and remove/add classes to make transition work).
I doubt is there any nice plugin to use.
Here's piece of my code, which inspired by Hardware-Accelerated Page Transitions for Mobile Web Apps / PhoneGap Apps.
const keyHistory = [];
let dir = 0;
const PageMixin = {
componentWillAppear(cb) {
keyHistory.push(this.props.location.key);
let $el = $(ReactDom.findDOMNode(this));
$el.addClass(pageStyles.right);
$el.one('transitionend', () => {
$el.removeClass(`${pageStyles.right} ${pageStyles.active}`);
cb();
});
requestAnimationFrame(() => {
$el.addClass(`${pageStyles.active} ${pageStyles.center}`);
});
},
componentWillEnter(cb) {
let key = this.props.location.key,
len = keyHistory.length;
if (key === keyHistory[len - 2]) {
keyHistory.pop();
dir = -1;
} else {
keyHistory.push(key);
dir = 1;
}
const fromDir = dir === -1 ? pageStyles.left : pageStyles.right;
let $el = $(ReactDom.findDOMNode(this));
$el.addClass(fromDir);
requestAnimationFrame(() => {
$el.removeClass(fromDir).addClass(`${pageStyles.active} ${pageStyles.center}`);
});
$el.one('transitionend', () => {
$el.removeClass(`${fromDir} ${pageStyles.active}`);
cb();
});
},
componentWillLeave(cb) {
const toDir = dir === -1 ? pageStyles.right : pageStyles.left;
let $el = $(ReactDom.findDOMNode(this));
requestAnimationFrame(() => {
$el.removeClass(pageStyles.center).addClass(`${pageStyles.active} ${toDir}`);
});
$el.one('transitionend', () => {
$el.removeClass(pageStyles.active);
cb();
});
}
};