Skip to content

Commit 2e66905

Browse files
committed
🛸 _app: switch from react-transition-group to react-spring!
1 parent 6509db6 commit 2e66905

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

pages/_app.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import App, { Container } from 'next/app';
22
import React from 'react';
3-
import { TransitionGroup, CSSTransition } from 'react-transition-group';
3+
import styled from 'styled-components';
4+
import { Transition } from 'react-spring';
45
import AppNavigation from '../components/AppNavigation';
56
import AppFooter from '../components/AppFooter';
67
import data from '../tools/data';
@@ -57,22 +58,33 @@ export default class MyApp extends App {
5758
changeUser={this.changeUser}
5859
pathname={this.props.router.pathname}
5960
/>
60-
<TransitionGroup className="transition-group-wrapper">
61-
<CSSTransition
62-
classNames="page"
63-
key={this.props.router.pathname}
64-
timeout={250}
65-
>
66-
<Component
67-
{...pageProps}
68-
{...this.state}
69-
selectedUser={selectedUser}
70-
/>
71-
</CSSTransition>
72-
</TransitionGroup>
73-
<AppFooter />
61+
<Transition
62+
from={{ opacity: 0 }}
63+
enter={{ opacity: 1 }}
64+
leave={{ opacity: 0 }}
65+
keys={this.props.router.route}
66+
>
67+
{style => (
68+
<Positioner style={style}>
69+
<Component
70+
{...pageProps}
71+
{...this.state}
72+
selectedUser={selectedUser}
73+
/>
74+
<AppFooter />
75+
</Positioner>
76+
)}
77+
</Transition>
7478
</div>
7579
</Container>
7680
);
7781
}
7882
}
83+
84+
const Positioner = styled.div`
85+
position: absolute;
86+
display: flex;
87+
flex-direction: column;
88+
align-items: center;
89+
width: 100%;
90+
`;

pages/_styles.js

-22
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,4 @@ injectGlobal`
4646
font-family: 'Playfair Display', serif;
4747
font-weight: normal;
4848
}
49-
50-
.transition-group-wrapper {
51-
position: relative; /* xavier's dirty hack */
52-
}
53-
54-
.page-enter,
55-
.page-exit {
56-
opacity: 0;
57-
transition: all 0.25s ease;
58-
}
59-
60-
.page-enter-active,
61-
.page-exit-active {
62-
transition: all 0.25s ease;
63-
transform: translateZ(0);
64-
backface-visibility: hidden;
65-
}
66-
67-
.page-enter-active {
68-
opacity: 1;
69-
position: absolute; /* xavier's dirty hack */
70-
}
7149
`;

0 commit comments

Comments
 (0)