Skip to content

Commit

Permalink
Add touch event handlers to toggle drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun-Murakami committed Mar 4, 2024
1 parent 0bc54bc commit a76d77e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function ResponsiveDrawer({
const [drawerState, setDrawerState] = useState(false);
const [isMenuVisible, setIsMenuVisible] = useState(false);
const [isSwipe, setIsSwipe] = useState(false);
const [startTouch, setStartTouch] = useState<Touch | null>(null);

const darkMode = useAppStateStore((state) => state.darkMode);
const hideDoneItems = useAppStateStore((state) => state.hideDoneItems);
Expand Down Expand Up @@ -107,6 +108,18 @@ export function ResponsiveDrawer({
</>
);

const handleTouchStart = (event: React.TouchEvent) => {
setStartTouch(event.touches[0] as Touch | null);
};

const handleTouchEnd = (event: React.TouchEvent) => {
const endTouch = event.changedTouches[0];
// スクロールを検出する簡単な方法
if (startTouch && Math.abs(startTouch.pageY - endTouch.pageY) < 10) {
toggleDrawer(true);
}
};

return (
<>
{!currentTree && treesList.length === 0 && (
Expand All @@ -128,6 +141,8 @@ export function ResponsiveDrawer({
aria-label='open drawer'
edge='start'
onClick={toggleDrawer(true)}
onTouchStart={handleTouchStart}
onTouchEnd={handleTouchEnd}
size='large'
sx={{
border: `1px solid ${theme.palette.divider}`,
Expand All @@ -138,7 +153,6 @@ export function ResponsiveDrawer({
zIndex: 1000,
backgroundColor: theme.palette.background.default,
opacity: 1,
pointerEvents: 'all',
}}
>
<MenuIcon />
Expand Down

0 comments on commit a76d77e

Please sign in to comment.