Skip to content

Commit

Permalink
fix #550 for real
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Jan 24, 2021
1 parent aa0c65b commit 75840f5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/hooks/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ export function useToast(props: ToastProps) {
function onDragStart(
e: React.MouseEvent<HTMLElement, MouseEvent> | React.TouchEvent<HTMLElement>
) {
const toast = toastRef.current!;
drag.canCloseOnClick = true;
drag.canDrag = true;
drag.boundingRect = toast.getBoundingClientRect();
toast.style.transition = '';

if (props.draggableDirection === Direction.X) {
drag.start = drag.x = getX(e.nativeEvent as DragEvent);
drag.removalDistance = toast.offsetWidth * (props.draggablePercent / 100);
} else {
drag.start = drag.y = getY(e.nativeEvent as DragEvent);
drag.removalDistance =
toast.offsetHeight * (props.draggablePercent / 100);
if (props.draggable) {
const toast = toastRef.current!;
drag.canCloseOnClick = true;
drag.canDrag = true;
drag.boundingRect = toast.getBoundingClientRect();
toast.style.transition = '';

if (props.draggableDirection === Direction.X) {
drag.start = drag.x = getX(e.nativeEvent as DragEvent);
drag.removalDistance =
toast.offsetWidth * (props.draggablePercent / 100);
} else {
drag.start = drag.y = getY(e.nativeEvent as DragEvent);
drag.removalDistance =
toast.offsetHeight * (props.draggablePercent / 100);
}
}
}

Expand Down Expand Up @@ -153,11 +156,10 @@ export function useToast(props: ToastProps) {
}

function onDragMove(e: MouseEvent | TouchEvent) {
e.preventDefault();

const toast = toastRef.current!;

if (drag.canDrag) {
e.preventDefault();

const toast = toastRef.current!;
if (isRunning) pauseToast();

drag.x = getX(e as DragEvent);
Expand Down

0 comments on commit 75840f5

Please sign in to comment.