summaryrefslogtreecommitdiffhomepage
path: root/app/components/TransitionContainer.js
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-07-18 15:07:37 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-08-15 17:39:38 +0200
commit71592249b2dd669b6f24f37bfb7b0f4e43b74998 (patch)
treea6097dc7e5d94d06e99c65fdfe160e824395f50c /app/components/TransitionContainer.js
parente84e87f4ce5a8c242f756566cdc6fb59a45f7bea (diff)
downloadmullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.tar.xz
mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.zip
Add workspaces
Diffstat (limited to 'app/components/TransitionContainer.js')
-rw-r--r--app/components/TransitionContainer.js201
1 files changed, 0 insertions, 201 deletions
diff --git a/app/components/TransitionContainer.js b/app/components/TransitionContainer.js
deleted file mode 100644
index 2c1fb09995..0000000000
--- a/app/components/TransitionContainer.js
+++ /dev/null
@@ -1,201 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { Styles, Component, Animated, View, Types, UserInterface } from 'reactxp';
-import type { TransitionGroupProps } from '../transitions';
-import getStyles from './TransitionContainerStyles';
-
-type TransitionContainerProps = {
- children: React.Node,
- ...TransitionGroupProps,
-};
-
-type State = {
- previousChildren: ?React.Node,
- childrenAnimation: Types.AnimatedViewStyleRuleSet,
- previousChildrenAnimation: Types.AnimatedViewStyleRuleSet,
- animationStyles: Types.AnimatedViewStyleRuleSet,
- dimensions: Types.Dimensions,
-};
-
-export default class TransitionContainer extends Component<TransitionContainerProps, State> {
- constructor(props: TransitionContainerProps) {
- super(props);
-
- const dimensions = UserInterface.measureWindow();
-
- this.state = {
- dimensions,
- };
- }
-
- componentWillReceiveProps(nextProps: TransitionContainerProps) {
- switch (nextProps.name) {
- case 'slide-up':
- this.slideUpTransition(nextProps);
- break;
- case 'slide-down':
- this.slideDownTransition(nextProps);
- break;
- case 'push':
- this.pushTransition(nextProps);
- break;
- case 'pop':
- this.popTransition(nextProps);
- break;
- default:
- break;
- }
- }
-
- onFinishedAnimation() {
- this.setState({
- childrenAnimation: getStyles().allowPointerEventsStyle,
- previousChildren: null,
- });
- }
-
- slideUpTransition(nextProps: TransitionContainerProps) {
- const currentTranslationValue = Animated.createValue(this.state.dimensions.height);
- this.setState(
- {
- previousChildren: this.props.children,
- childrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 1,
- transform: [{ translateY: currentTranslationValue }],
- }),
- previousChildrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 0,
- transform: [{ translateY: 0 }],
- }),
- },
- () => {
- Animated.timing(currentTranslationValue, {
- toValue: 0,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }).start(() => this.onFinishedAnimation());
- },
- );
- }
-
- slideDownTransition(nextProps: TransitionContainerProps) {
- const previousTranslationValue = Animated.createValue(0);
- this.setState(
- {
- previousChildren: this.props.children,
- childrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 0,
- transform: [{ translateY: 0 }],
- }),
- previousChildrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 1,
- transform: [{ translateY: previousTranslationValue }],
- }),
- },
- () => {
- Animated.timing(previousTranslationValue, {
- toValue: this.state.dimensions.height,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }).start(() => this.onFinishedAnimation());
- },
- );
- }
-
- pushTransition(nextProps: TransitionContainerProps) {
- const currentTranslationValue = Animated.createValue(this.state.dimensions.width);
- const previousTranslationValue = Animated.createValue(0);
- this.setState(
- {
- previousChildren: this.props.children,
- childrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 1,
- transform: [{ translateX: currentTranslationValue }],
- }),
- previousChildrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 0,
- transform: [{ translateX: previousTranslationValue }],
- }),
- },
- () => {
- const compositeAnimation = Animated.parallel([
- Animated.timing(currentTranslationValue, {
- toValue: 0,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }),
- Animated.timing(previousTranslationValue, {
- toValue: -this.state.dimensions.width / 2,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }),
- ]);
- compositeAnimation.start(() => this.onFinishedAnimation());
- },
- );
- }
-
- popTransition(nextProps: TransitionContainerProps) {
- const currentTranslationValue = Animated.createValue(-this.state.dimensions.width / 2);
- const previousTranslationValue = Animated.createValue(0);
- this.setState(
- {
- previousChildren: this.props.children,
- childrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 0,
- transform: [{ translateX: currentTranslationValue }],
- }),
- previousChildrenAnimation: Styles.createAnimatedViewStyle({
- pointerEvents: 'none',
- zIndex: 1,
- transform: [{ translateX: previousTranslationValue }],
- }),
- },
- () => {
- const compositeAnimation = Animated.parallel([
- Animated.timing(currentTranslationValue, {
- toValue: 0,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }),
- Animated.timing(previousTranslationValue, {
- toValue: this.state.dimensions.width,
- easing: Animated.Easing.InOut(),
- duration: nextProps.duration,
- }),
- ]);
- compositeAnimation.start(() => this.onFinishedAnimation());
- },
- );
- }
-
- render() {
- const { children } = this.props;
- const { previousChildren, childrenAnimation, previousChildrenAnimation } = this.state;
- return (
- <View style={getStyles().transitionContainerStyle}>
- {previousChildren && (
- <Animated.View
- key={previousChildren && previousChildren.key}
- style={[getStyles().animationDefaultStyle, previousChildrenAnimation]}>
- {previousChildren}
- </Animated.View>
- )}
-
- <Animated.View
- key={children.key}
- style={[getStyles().animationDefaultStyle, childrenAnimation]}>
- {children}
- </Animated.View>
- </View>
- );
- }
-}