diff --git a/src/components/auth/PanelTransition.jsx b/src/components/auth/PanelTransition.jsx index 98a8dd5..8185a48 100644 --- a/src/components/auth/PanelTransition.jsx +++ b/src/components/auth/PanelTransition.jsx @@ -10,14 +10,14 @@ import icons from 'components/ui/icons.scss'; const opacitySpringConfig = [200, 20]; -const heightSpringConfig = [200, 18]; -const transformSpringConfig = [500, 20]; +const transformSpringConfig = [500, 50]; // TODO: сделать более быстрый фейд на горизонтальном скролле export default class PanelTransition extends Component { state = { - height: {} + height: {}, + contextHeight: 0 }; componentWillReceiveProps(nextProps) { @@ -27,9 +27,10 @@ export default class PanelTransition extends Component { var prev = previousRoute && previousRoute.pathname; var direction = this.getDirection(next, next, prev); - var forceHeight = direction === 'Y' ? 1 : 0; + var forceHeight = direction === 'Y' && next !== prev ? 1 : 0; this.setState({ + direction, forceHeight: forceHeight, previousRoute: this.props.location }); @@ -42,9 +43,9 @@ export default class PanelTransition extends Component { } render() { - var {previousRoute, height} = this.state; + var {previousRoute, height, contextHeight, forceHeight} = this.state; - var {path, Title, Body, Footer, Links} = this.props; + const {path, Title, Body, Footer, Links} = this.props; return ( this.getHeader(key, items[key]))} - -
- {keys.map((key) => this.getBody(key, items[key]))} -
-
- -
- {keys.map((key) => this.getFooter(key, items[key]))} -
-
+ + +
+ {keys.map((key) => this.getBody(key, items[key]))} +
+
+ +
+ {keys.map((key) => this.getFooter(key, items[key]))} +
+
+
+
{keys.map((key) => this.getLinks(key, items[key]))} @@ -152,12 +161,32 @@ export default class PanelTransition extends Component { }); }; + updateContextHeight = (height) => { + this.setState({ + contextHeight: height + }); + }; + onGoBack = (event) => { event.preventDefault(); this.props.history.goBack(); }; + 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]; + } + getHeader(key, props) { var {hasBackButton, transformSpring, Title} = props; @@ -198,21 +227,18 @@ export default class PanelTransition extends Component { getBody(key, props) { var {transformSpring, opacitySpring, Body} = props; - var {previousRoute} = this.state; + var {direction} = this.state; - var next = this.props.path; - var prev = previousRoute && previousRoute.pathname; + var transform = { + WebkitTransform: `translate${direction}(${transformSpring}%)`, + transform: `translate${direction}(${transformSpring}%)` + }; - var direction = this.getDirection(key, next, prev); var verticalOrigin = 'top'; - if (direction === 'Y') { // TODO: do not activate animation when nothing was unmounted - transformSpring = Math.abs(transformSpring); - if (prev === key) { - transformSpring *= -1; - } - + if (direction === 'Y') { verticalOrigin = 'bottom'; + transform = {}; } var style = { @@ -220,9 +246,8 @@ export default class PanelTransition extends Component { [verticalOrigin]: 0, left: 0, width: '100%', - WebkitTransform: `translate${direction}(${transformSpring}%)`, - transform: `translate${direction}(${transformSpring}%)`, - opacity: opacitySpring + opacity: opacitySpring, + ...transform }; return ( @@ -232,20 +257,6 @@ 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) { var {opacitySpring, Footer} = props;