Skip to content

Commit

Permalink
fix: mobile drag
Browse files Browse the repository at this point in the history
  • Loading branch information
hatchling13 committed Mar 28, 2024
1 parent 7c81a93 commit 76f3cf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DragOverlay,
KeyboardSensor,
PointerSensor,
TouchSensor,
closestCenter,
useSensor,
useSensors,
Expand All @@ -29,8 +30,14 @@ import type { TSpotState } from '@/context/travel/schema';
import SortableSpot from './SortableSpot';

export default function AddCourseOrder() {
const sensor =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
? TouchSensor
: PointerSensor;
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
useSensor(sensor, { activationConstraint: { distance: 5 } }),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/app/_components/images/ImagesContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DragOverlay,
KeyboardSensor,
PointerSensor,
TouchSensor,
useSensor,
useSensors,
} from '@dnd-kit/core';
Expand Down Expand Up @@ -37,8 +38,15 @@ export default function ImagesContainer({
setImages: (newImages: { type: 'new'; data: TImageData[] }) => void;
}) {
const [activeId, setActiveId] = useState<string | null>(null);

const sensor =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
? TouchSensor
: PointerSensor;
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 1 } }),
useSensor(sensor, { activationConstraint: { distance: 5 } }),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DragStartEvent,
KeyboardSensor,
PointerSensor,
TouchSensor,
UniqueIdentifier,
useSensor,
useSensors,
Expand Down Expand Up @@ -42,8 +43,15 @@ export default function CourseSpotContainer({
onClickDeleteSpot: (e: EventFor<'span', 'onClick'>, id: number) => void;
}) {
const [activeId, setActiveId] = useState<number | null>(null);

const sensor =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
? TouchSensor
: PointerSensor;
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
useSensor(sensor, { activationConstraint: { distance: 5 } }),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
Expand Down

0 comments on commit 76f3cf2

Please sign in to comment.