Еще одна версия анимации и более правильный алгоритм переключения

вертикальной/горизонтальной анимации
This commit is contained in:
SleepWalker 2016-02-03 07:36:00 +02:00
parent 8792333131
commit 13d220087f

View File

@ -20,17 +20,26 @@ export default class PanelTransition extends Component {
height: {} height: {}
}; };
componentWillReceiveProps() { componentWillReceiveProps(nextProps) {
var previousRoute = this.props.location;
var next = nextProps.path;
var prev = previousRoute && previousRoute.pathname;
var direction = this.getDirection(next, next, prev);
var forceHeight = direction === 'Y' ? 1 : 0;
this.setState({ this.setState({
forceHeight: window.forceHeight, forceHeight: forceHeight,
previousRoute: this.props.location previousRoute: this.props.location
}); });
if (forceHeight) {
setTimeout(() => { setTimeout(() => {
this.setState({forceHeight: 0}); this.setState({forceHeight: 0});
window.forceHeight = 0;
}, 100); }, 100);
} }
}
render() { render() {
var {previousRoute, height} = this.state; var {previousRoute, height} = this.state;
@ -46,11 +55,11 @@ export default class PanelTransition extends Component {
Footer, Footer,
Links, Links,
hasBackButton: previousRoute && previousRoute.pathname === Title.type.goBack, hasBackButton: previousRoute && previousRoute.pathname === Title.type.goBack,
transformSpring: spring(0), transformSpring: spring(0, transformSpringConfig),
opacitySpring: spring(1) opacitySpring: spring(1, opacitySpringConfig)
}, },
common: { common: {
heightSpring: spring(this.state.forceHeight || height[path] || 0, heightSpringConfig) heightSpring: spring(this.state.forceHeight || height[path] || 0, transformSpringConfig)
} }
}} }}
willEnter={this.willEnter} willEnter={this.willEnter}
@ -189,33 +198,21 @@ export default class PanelTransition extends Component {
getBody(key, props) { getBody(key, props) {
var {transformSpring, opacitySpring, Body} = props; var {transformSpring, opacitySpring, Body} = props;
var {previousRoute} = this.state; var {previousRoute} = this.state;
var next = this.props.path; var next = this.props.path;
var prev = previousRoute && previousRoute.pathname; var prev = previousRoute && previousRoute.pathname;
var not = (path) => prev !== path && next !== path; var direction = this.getDirection(key, next, prev);
var map = {
'/login': not('/password') ? 'Y' : 'X',
'/password': not('/login') ? 'Y' : 'X',
'/register': not('/activation') ? 'Y' : 'X',
'/activation': not('/register') ? 'Y' : 'X',
'/oauth/permissions': 'Y'
};
var direction = map[key];
var verticalOrigin = 'top'; var verticalOrigin = 'top';
if (direction === 'Y') { if (direction === 'Y') { // TODO: do not activate animation when nothing was unmounted
transformSpring = Math.abs(transformSpring); transformSpring = Math.abs(transformSpring);
if (prev === key) { if (prev === key) {
transformSpring *= -1; transformSpring *= -1;
} }
verticalOrigin = 'bottom'; verticalOrigin = 'bottom';
window.forceHeight = 1;
} }
var style = { var style = {
@ -235,6 +232,20 @@ export default class PanelTransition extends Component {
); );
} }
getDirection(key, next, prev) {
var not = (path) => prev !== path && next !== path;
var map = {
'/login': not('/password') ? 'Y' : 'X',
'/password': not('/login') ? 'Y' : 'X',
'/register': not('/activation') ? 'Y' : 'X',
'/activation': not('/register') ? 'Y' : 'X',
'/oauth/permissions': 'Y'
};
return map[key];
}
getFooter(key, props) { getFooter(key, props) {
var {opacitySpring, Footer} = props; var {opacitySpring, Footer} = props;