-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
89 lines (81 loc) · 2.2 KB
/
App.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
83
84
85
86
87
88
89
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import { Transition } from 'react-transition-group';
import { TimelineLite } from 'gsap/TweenMax';
import logo from './logo.svg';
import './App.css';
/* eslint-disable default-case */
class Page1 extends Component {
componentDidMount() {
this.props.tl
.from(this.body, 2, { x: '-100%' })
.from(this.header, 2, { opacity: 0 }, '-=2');
}
componentWillUnmount() {
this.props.tl.clear();
}
render() {
return (
<div className="App">
<header ref={x => (this.header = x)} className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">
Homepage transition status: {this.props.status}
</h1>
</header>
<p className="App-body" ref={x => (this.body = x)}>
This is an animated home page.{' '}
<Link to="/another">Go another route</Link>
</p>
</div>
);
}
}
const Page2 = () => (
<p>
Hi from another route. <Link to="/">Go back</Link>
</p>
);
class App extends React.Component {
constructor() {
super();
this.tl = new TimelineLite({ paused: true });
window.tl = this.tl;
this.homeTransition = this.homeTransition.bind(this);
}
homeTransition(_, status, done) {
console.log('homeTransition');
this.tl.eventCallback('onComplete', done);
this.tl.eventCallback('onReverseComplete', done);
switch (status) {
case 'entering':
this.tl.play();
break;
case 'exiting':
this.tl.reverse();
}
}
render() {
return (
<Router>
<React.Fragment>
<Route exact path="/">
{({ match }) => (
<Transition
appear
in={!!match}
mountOnEnter
unmountOnExit
addEndListener={this.homeTransition}
>
{status => <Page1 status={status} tl={this.tl} />}
</Transition>
)}
</Route>
<Route path="/another" component={Page2} />
</React.Fragment>
</Router>
);
}
}
export default App;