Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Experiment with a fix for Safari iOS #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix: Experiment with a fix for Safari iOS
forabi committed Apr 8, 2019
commit 05b362d4a26fff23f19433e2fa916b89f160d26a
37 changes: 37 additions & 0 deletions src/components/RangeBox.tsx
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ export const RangeBox = React.memo(function RangeBox({
modifiedCell,
grid,
]);
const [isInteracting, setIsInteracting] = useState(false);

useEffect(() => {
setModifiedCell(cell);
@@ -63,6 +64,8 @@ export const RangeBox = React.memo(function RangeBox({
const isEnd = cellIndex === cellArray.length - 1;

const handleStop = useCallback(() => {
setIsInteracting(false);

if (!onChange || disabled) {
return;
}
@@ -185,6 +188,7 @@ export const RangeBox = React.memo(function RangeBox({
return;
}

setIsInteracting(true);
event.preventDefault();
event.stopPropagation();

@@ -236,6 +240,7 @@ export const RangeBox = React.memo(function RangeBox({
return;
}

setIsInteracting(true);
event.preventDefault();
event.stopPropagation();

@@ -309,6 +314,36 @@ export const RangeBox = React.memo(function RangeBox({
[classes.handle],
);

const preventDefaultIfInteracting = useCallback(
e => {
if (isInteracting) {
e.preventDefault();
}
},
[isInteracting],
);

useEffect(() => {
document.body.addEventListener('touchmove', preventDefaultIfInteracting, {
passive: false,
});
document.body.addEventListener('scroll', preventDefaultIfInteracting, {
passive: false,
});

return () => {
document.body.removeEventListener(
'touchmove',
preventDefaultIfInteracting,
);
document.body.removeEventListener('scroll', preventDefaultIfInteracting);
};
}, [preventDefaultIfInteracting]);

const touchAction = useMemo(() => {
return isInteracting ? 'none' : undefined;
}, [isInteracting]);

return (
<Draggable
axis={moveAxis}
@@ -318,6 +353,7 @@ export const RangeBox = React.memo(function RangeBox({
left: 0,
right: grid.totalWidth,
}}
touch-action={touchAction}
position={{ x: left, y: top }}
onDrag={handleDrag}
onStop={handleStop}
@@ -326,6 +362,7 @@ export const RangeBox = React.memo(function RangeBox({
>
<EventRootComponent
role="button"
touch-action={touchAction}
disabled={disabled}
onFocus={handleOnFocus}
onClick={handleOnClick}