From 52ed76a02f7e90c054443508a275f39fc8da54c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 29 Jun 2023 18:33:06 +0200 Subject: [PATCH] Double click to cycle size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/video-grid/NewVideoGrid.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/video-grid/NewVideoGrid.tsx b/src/video-grid/NewVideoGrid.tsx index b88128d..d6c3718 100644 --- a/src/video-grid/NewVideoGrid.tsx +++ b/src/video-grid/NewVideoGrid.tsx @@ -257,6 +257,11 @@ export function NewVideoGrid({ ); }; + const [lastTappedTileId, setLastTappedTileId] = useState( + undefined + ); + const [lastTapTime, setLastTapTime] = useState(0); + // Callback for useDrag. We could call useDrag here, but the default // pattern of spreading {...bind()} across the children to bind the gesture // ends up breaking memoization and ruining this component's performance. @@ -272,7 +277,14 @@ export function NewVideoGrid({ }: Parameters>[0] ) => { if (tap) { - toggleFocus?.(items.find((i) => i.id === tileId)!); + const now = Date.now(); + + if (tileId === lastTappedTileId && now - lastTapTime < 500) { + toggleFocus?.(items.find((i) => i.id === tileId)!); + } + + setLastTappedTileId(tileId); + setLastTapTime(now); } else { const tileController = springRef.current.find( (c) => (c.item as Tile).item.id === tileId