This repository was archived by the owner on Aug 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapplication.js
82 lines (74 loc) · 2.21 KB
/
application.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* @flow */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import Landing from './landing';
import ApplicationView from './application-view';
import LoginView from './login-view';
export default class Application extends Component {
static propTypes = {
token: PropTypes.string,
selectedProjectKey: PropTypes.string,
setToken: PropTypes.func.isRequired,
setProjectKey: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
};
state = {
isAnimating: true,
};
animatedValue = new Animated.Value(0);
animatedStyle = { transform: [{ translateY: this.animatedValue }] };
componentDidMount = () => {
const endAnimation = this.props.token
? [
// If the user is logged in, end the animation outside the screen
Animated.spring(this.animatedValue, {
toValue: -400,
friction: 10,
tension: 50,
velocity: 1,
useNativeDriver: true,
}),
]
: [
// If the user is not logged in, end the animation more or less
// in the center of the screen.
Animated.spring(this.animatedValue, {
// This position is where the logo will be shown in the
// login screen.
toValue: -88,
friction: 10,
tension: 50,
useNativeDriver: true,
}),
];
// Define a sequence of animations before starting the application.
// - wait 1sec
// - move down
// - end the animation (see above)
Animated.sequence([
Animated.timing(this.animatedValue, {
toValue: 0,
duration: 1000,
useNativeDriver: true,
}),
Animated.timing(this.animatedValue, {
toValue: 50,
duration: 200,
useNativeDriver: true,
}),
...endAnimation,
]).start(() => {
this.setState({ isAnimating: false });
});
};
render = () => {
if (this.state.isAnimating)
return <Landing animatedStyle={this.animatedStyle} />;
if (this.props.token)
return <ApplicationView {...this.props} />;
return (
<LoginView onLogin={this.props.setToken} />
);
};
}