Skip to content

Commit

Permalink
Refactor drawer menu visibility logic and improve drag and drop behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun-Murakami committed Feb 25, 2024
1 parent 74e9727 commit 5e5f2ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 10 additions & 3 deletions src/components/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ export function ResponsiveDrawer({
if (isSwipe && drawerState) {
setIsMenuVisible(false);
} else if (!isSwipe && drawerState) {
setIsMenuVisible(true);
const setTimer = setTimeout(() => {
// drawerStateがfalseになっているかチェック
if (!drawerState) {
return;
}
setIsMenuVisible(true);
}, 170);
return () => clearTimeout(setTimer);
} else {
setIsMenuVisible(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSwipe]);
// drawerStateを依存配列に追加
}, [isSwipe, drawerState]);

const theme = useTheme();

Expand Down
18 changes: 4 additions & 14 deletions src/components/SortableList/SortableList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useState } from 'react';
import { DndContext, DragOverlay, UniqueIdentifier, closestCenter, defaultDropAnimationSideEffects } from '@dnd-kit/core';
import { DndContext, DragOverlay, UniqueIdentifier, closestCenter } from '@dnd-kit/core';
import { arrayMove, SortableContext } from '@dnd-kit/sortable';
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';

Expand Down Expand Up @@ -31,8 +31,8 @@ export const SortableList: FC<SortableListProps> = ({
return (
<>
<DndContext
collisionDetection={closestCenter}
modifiers={[restrictToVerticalAxis]}
collisionDetection={closestCenter} // ドラッグ中の要素の中心を検出
modifiers={[restrictToVerticalAxis]} // 縦方向のみの移動に制限
onDragStart={(event) => {
setActiveId(event.active.id as number);
}}
Expand Down Expand Up @@ -60,17 +60,7 @@ export const SortableList: FC<SortableListProps> = ({
/>
))}
</SortableContext>
<DragOverlay
dropAnimation={
isPreviewMode
? {
sideEffects: defaultDropAnimationSideEffects({
styles: {},
}),
}
: undefined
}
>
<DragOverlay>
{activeItem && (
<SortableSource
item={activeItem}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SortableList/SortableSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const SortableSource: FC<SortableSourceProps> = ({ item, handlerProps, cu
minWidth: '20px',
height: '20px',
mr: '10px',
touchAction: 'none',
zIndex: 1500,
}}
{...handlerProps?.attributes}
{...handlerProps?.listeners}
Expand Down

0 comments on commit 5e5f2ef

Please sign in to comment.