From 57d30f1c792b7bb2bdf2835cd6c5af25e05f26ab Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 6 Feb 2016 11:03:51 +0200 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B1=D1=8B?= =?UTF-8?q?=20=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/PanelTransition.jsx | 115 +++++++++++++----------- 1 file changed, 63 insertions(+), 52 deletions(-) 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;