From 36ad83ac6d81d4f5bc54fe953870711295e27c55 Mon Sep 17 00:00:00 2001 From: Ella Date: Sat, 29 Jun 2024 17:05:49 +0300 Subject: [PATCH] Add swipe for list --- src/index.js | 7 ------- src/list.jsx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 89ef903..66b9a79 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,4 @@ import { Filesystem } from '@capacitor/filesystem'; -import { App as NativeApp } from '@capacitor/app'; import { Preferences } from '@capacitor/preferences'; import { get } from 'idb-keyval'; import { createRoot } from 'react-dom/client'; @@ -59,12 +58,6 @@ async function load() { registerCoreBlocks(); root.render(app({ selectedFolderURL, canUseNativeFilesystem })); - - NativeApp.addListener('appStateChange', ({ isActive }) => { - if (!isActive) { - // save - } - }); } load(); diff --git a/src/list.jsx b/src/list.jsx index b7bbeb5..292c631 100644 --- a/src/list.jsx +++ b/src/list.jsx @@ -102,6 +102,39 @@ export default function Frame({ selectedFolderURL, setSelectedFolderURL }) { ); }, []); + useEffect(() => { + if (isSidebarOpen) { + return; + } + + let startTouchX = 0; + + document.addEventListener('touchstart', handleTouchStart); + document.addEventListener('touchmove', handleTouchMove); + + function handleTouchStart(event) { + startTouchX = event.touches[0].clientX; + } + + function handleTouchMove(event) { + if (event.touches.length > 1) { + return; + } + + const touchX = event.touches[0].clientX; + const deltaX = touchX - startTouchX; + + if (deltaX > 50 && startTouchX < 20) { + setIsSidebarOpen(true); + } + } + + return () => { + document.removeEventListener('touchstart', handleTouchStart); + document.removeEventListener('touchmove', handleTouchMove); + }; + }, [isSidebarOpen, setIsSidebarOpen]); + useEffect(() => { setItems([]); setCurrentId();