Skip to content

Commit 8d2bb78

Browse files
committed
Add fixture
1 parent 74c1b84 commit 8d2bb78

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

fixtures/view-transition/src/components/Page.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@
66
font-variation-settings:
77
"wdth" 100;
88
}
9+
10+
.swipe-recognizer {
11+
width: 200px;
12+
overflow-x: scroll;
13+
border: 1px solid #333333;
14+
border-radius: 10px;
15+
}
16+
17+
.swipe-overscroll {
18+
width: 200%;
19+
}

fixtures/view-transition/src/components/Page.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, {
22
unstable_ViewTransition as ViewTransition,
33
unstable_Activity as Activity,
4+
unstable_useSwipeTransition as useSwipeTransition,
5+
useRef,
6+
useLayoutEffect,
47
} from 'react';
58

69
import './Page.css';
@@ -35,7 +38,8 @@ function Component() {
3538
}
3639

3740
export default function Page({url, navigate}) {
38-
const show = url === '/?b';
41+
const [renderedUrl, startGesture] = useSwipeTransition('/?a', url, '/?b');
42+
const show = renderedUrl === '/?b';
3943
function onTransition(viewTransition, types) {
4044
const keyframes = [
4145
{rotate: '0deg', transformOrigin: '30px 8px'},
@@ -44,6 +48,32 @@ export default function Page({url, navigate}) {
4448
viewTransition.old.animate(keyframes, 250);
4549
viewTransition.new.animate(keyframes, 250);
4650
}
51+
52+
const swipeRecognizer = useRef(null);
53+
const activeGesture = useRef(null);
54+
function onScroll() {
55+
if (activeGesture.current !== null) {
56+
return;
57+
}
58+
// eslint-disable-next-line no-undef
59+
const scrollTimeline = new ScrollTimeline({
60+
source: swipeRecognizer.current,
61+
axis: 'x',
62+
});
63+
activeGesture.current = startGesture(scrollTimeline);
64+
}
65+
function onScrollEnd() {
66+
if (activeGesture.current !== null) {
67+
const cancelGesture = activeGesture.current;
68+
activeGesture.current = null;
69+
cancelGesture();
70+
}
71+
}
72+
73+
useLayoutEffect(() => {
74+
swipeRecognizer.current.scrollLeft = show ? 0 : 10000;
75+
}, [show]);
76+
4777
const exclamation = (
4878
<ViewTransition name="exclamation" onShare={onTransition}>
4979
<span>!</span>
@@ -90,6 +120,13 @@ export default function Page({url, navigate}) {
90120
<p></p>
91121
<p></p>
92122
<p></p>
123+
<div
124+
className="swipe-recognizer"
125+
onScroll={onScroll}
126+
onScrollEnd={onScrollEnd}
127+
ref={swipeRecognizer}>
128+
<div className="swipe-overscroll">Swipe me</div>
129+
</div>
93130
<p></p>
94131
<p></p>
95132
{show ? null : (

0 commit comments

Comments
 (0)