From 8d2bb78291ed5f9242207137717bbd94af4fe0b6 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Wed, 12 Feb 2025 19:44:23 -0500 Subject: [PATCH] Add fixture --- .../view-transition/src/components/Page.css | 11 ++++++ .../view-transition/src/components/Page.js | 39 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/fixtures/view-transition/src/components/Page.css b/fixtures/view-transition/src/components/Page.css index 5afcc33a8f4bc..a5a9373194ef8 100644 --- a/fixtures/view-transition/src/components/Page.css +++ b/fixtures/view-transition/src/components/Page.css @@ -6,3 +6,14 @@ font-variation-settings: "wdth" 100; } + +.swipe-recognizer { + width: 200px; + overflow-x: scroll; + border: 1px solid #333333; + border-radius: 10px; +} + +.swipe-overscroll { + width: 200%; +} diff --git a/fixtures/view-transition/src/components/Page.js b/fixtures/view-transition/src/components/Page.js index 40f60327728fd..1c7a9bfeb32db 100644 --- a/fixtures/view-transition/src/components/Page.js +++ b/fixtures/view-transition/src/components/Page.js @@ -1,6 +1,9 @@ import React, { unstable_ViewTransition as ViewTransition, unstable_Activity as Activity, + unstable_useSwipeTransition as useSwipeTransition, + useRef, + useLayoutEffect, } from 'react'; import './Page.css'; @@ -35,7 +38,8 @@ function Component() { } export default function Page({url, navigate}) { - const show = url === '/?b'; + const [renderedUrl, startGesture] = useSwipeTransition('/?a', url, '/?b'); + const show = renderedUrl === '/?b'; function onTransition(viewTransition, types) { const keyframes = [ {rotate: '0deg', transformOrigin: '30px 8px'}, @@ -44,6 +48,32 @@ export default function Page({url, navigate}) { viewTransition.old.animate(keyframes, 250); viewTransition.new.animate(keyframes, 250); } + + const swipeRecognizer = useRef(null); + const activeGesture = useRef(null); + function onScroll() { + if (activeGesture.current !== null) { + return; + } + // eslint-disable-next-line no-undef + const scrollTimeline = new ScrollTimeline({ + source: swipeRecognizer.current, + axis: 'x', + }); + activeGesture.current = startGesture(scrollTimeline); + } + function onScrollEnd() { + if (activeGesture.current !== null) { + const cancelGesture = activeGesture.current; + activeGesture.current = null; + cancelGesture(); + } + } + + useLayoutEffect(() => { + swipeRecognizer.current.scrollLeft = show ? 0 : 10000; + }, [show]); + const exclamation = ( ! @@ -90,6 +120,13 @@ export default function Page({url, navigate}) {

+
+
Swipe me
+

{show ? null : (