Skip to content

Commit

Permalink
Merge pull request #34406 from tienifr/fix/34349
Browse files Browse the repository at this point in the history
fix: drag drop file safari
  • Loading branch information
amyevans authored Jan 15, 2024
2 parents 996937b + 7b40424 commit 8480295
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useDragAndDrop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useIsFocused} from '@react-navigation/native';
import type React from 'react';
import {useCallback, useContext, useEffect, useState} from 'react';
import {useCallback, useContext, useEffect, useRef, useState} from 'react';
import type {View} from 'react-native';
import {PopoverContext} from '@components/PopoverProvider';

Expand Down Expand Up @@ -31,6 +31,8 @@ export default function useDragAndDrop({dropZone, onDrop = () => {}, shouldAllow
const [isDraggingOver, setIsDraggingOver] = useState(false);
const {close: closePopover} = useContext(PopoverContext);

const enterTarget = useRef<EventTarget | null>(null);

useEffect(() => {
if (isFocused && !isDisabled) {
return;
Expand Down Expand Up @@ -76,6 +78,7 @@ export default function useDragAndDrop({dropZone, onDrop = () => {}, shouldAllow
break;
case DRAG_ENTER_EVENT:
handleDragEvent(event);
enterTarget.current = event.target;
if (isDraggingOver) {
return;
}
Expand All @@ -86,7 +89,7 @@ export default function useDragAndDrop({dropZone, onDrop = () => {}, shouldAllow
return;
}
// This is necessary because dragging over children will cause dragleave to execute on the parent.
if ((event.currentTarget as HTMLElement | null)?.contains(event.relatedTarget as HTMLElement | null)) {
if (enterTarget.current !== event.target) {
return;
}

Expand Down

0 comments on commit 8480295

Please sign in to comment.