mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 16:35:49 +01:00
Fix mobile controls
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { Collapse, createStyles, Stack, Text } from '@mantine/core';
|
import { Collapse, createStyles, Flex, Stack, Text } from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
import { IconChevronDown, IconGripVertical } from '@tabler/icons';
|
import { IconChevronDown, IconGripVertical } from '@tabler/icons';
|
||||||
import { Reorder, useDragControls } from 'framer-motion';
|
import { Reorder, useDragControls } from 'framer-motion';
|
||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode, useEffect, useRef } from 'react';
|
||||||
import { IDraggableListInputValue } from '../../../../widgets/widgets';
|
import { IDraggableListInputValue } from '../../../../widgets/widgets';
|
||||||
|
|
||||||
const useStyles = createStyles((theme) => ({
|
const useStyles = createStyles((theme) => ({
|
||||||
@@ -83,16 +83,32 @@ const ListItem: FC<{
|
|||||||
const [opened, handlers] = useDisclosure(false);
|
const [opened, handlers] = useDisclosure(false);
|
||||||
const hasContent = props.children != null && Object.keys(props.children).length !== 0;
|
const hasContent = props.children != null && Object.keys(props.children).length !== 0;
|
||||||
|
|
||||||
|
// Workaround for mobile drag controls not working
|
||||||
|
// https://github.com/framer/motion/issues/1597#issuecomment-1235026724
|
||||||
|
const dragRef = useRef<HTMLDivElement>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
const touchHandler: EventListener = (e) => e.preventDefault();
|
||||||
|
|
||||||
|
const dragItem = dragRef.current;
|
||||||
|
|
||||||
|
if (dragItem) {
|
||||||
|
dragItem.addEventListener('touchstart', touchHandler, { passive: false });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
dragItem.removeEventListener('touchstart', touchHandler);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}, [dragRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Reorder.Item value={props.item.key} dragListener={false} dragControls={controls} as="div">
|
<Reorder.Item value={props.item.key} dragListener={false} dragControls={controls} as="div">
|
||||||
<div className={classes.container}>
|
<div className={classes.container}>
|
||||||
<div className={classes.row}>
|
<div className={classes.row}>
|
||||||
<IconGripVertical
|
<Flex ref={dragRef} onPointerDown={(e) => controls.start(e)}>
|
||||||
className={classes.clickableIcons}
|
<IconGripVertical className={classes.clickableIcons} size={18} stroke={1.5} />
|
||||||
onPointerDown={(e) => controls.start(e)}
|
</Flex>
|
||||||
size={18}
|
|
||||||
stroke={1.5}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className={classes.middle}>
|
<div className={classes.middle}>
|
||||||
<Text className={classes.symbol}>{props.label}</Text>
|
<Text className={classes.symbol}>{props.label}</Text>
|
||||||
|
|||||||
Reference in New Issue
Block a user