forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPage.js
More file actions
110 lines (104 loc) · 2.61 KB
/
Page.js
File metadata and controls
110 lines (104 loc) · 2.61 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, {
unstable_ViewTransition as ViewTransition,
unstable_Activity as Activity,
} from 'react';
import './Page.css';
import transitions from './Transitions.module.css';
const a = (
<div key="a">
<ViewTransition>
<div>a</div>
</ViewTransition>
</div>
);
const b = (
<div key="b">
<ViewTransition>
<div>b</div>
</ViewTransition>
</div>
);
function Component() {
return (
<ViewTransition
className={
transitions['enter-slide-right'] + ' ' + transitions['exit-slide-left']
}>
<p className="roboto-font">Slide In from Left, Slide Out to Right</p>
</ViewTransition>
);
}
export default function Page({url, navigate}) {
const show = url === '/?b';
function onTransition(viewTransition, types) {
const keyframes = [
{rotate: '0deg', transformOrigin: '30px 8px'},
{rotate: '360deg', transformOrigin: '30px 8px'},
];
viewTransition.old.animate(keyframes, 250);
viewTransition.new.animate(keyframes, 250);
}
const exclamation = (
<ViewTransition name="exclamation" onShare={onTransition}>
<span>!</span>
</ViewTransition>
);
return (
<div>
<button
onClick={() => {
navigate(show ? '/?a' : '/?b');
}}>
{show ? 'A' : 'B'}
</button>
<ViewTransition className="none">
<div>
<ViewTransition className={transitions['slide-on-nav']}>
<h1>{!show ? 'A' : 'B'}</h1>
</ViewTransition>
<ViewTransition
className={{
'navigation-back': transitions['slide-right'],
'navigation-forward': transitions['slide-left'],
}}>
<h1>{!show ? 'A' : 'B'}</h1>
</ViewTransition>
{show ? (
<div>
{a}
{b}
</div>
) : (
<div>
{b}
{a}
</div>
)}
<ViewTransition>
{show ? <div>hello{exclamation}</div> : <section>Loading</section>}
</ViewTransition>
<p>scroll me</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
{show ? null : (
<ViewTransition>
<div>world{exclamation}</div>
</ViewTransition>
)}
<Activity mode={show ? 'visible' : 'hidden'}>
<ViewTransition>
<div>!!</div>
</ViewTransition>
</Activity>
{show ? <Component /> : null}
</div>
</ViewTransition>
</div>
);
}