You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every usePinch event seems to fire at least twice on Safari.
Example
usePinch((state)=>{const{ timeStamp }=state;console.log(timeStamp);},{target: yourTargetHere});
...
return(<divref={yourTargetHere}style={{position: 'relative',touchAction: 'none'}}>
My component is in here.
</div>);
For posterity, here's how I've been coping. It's a bit janky. Admittedly, I could be foolish for not trusting it only ever to happen twice (returning timeStamp and comparing it to memo is the one-liner solution.)
Lmk if you have any ideas or, if it turns out this is by design, the proper way of dealing with it.
consttimestampSetRef=useRef<Set<number>>(newSet());constisRepeat=(n: number)=>{constisRe=timestampSetRef.current.has(n);// Update the set manuallytimestampSetRef.current.add(n);// If the set exceeds 16 elements, remove the oldest oneif(timestampSetRef.current.size>16){// Convert to an array, shift, and recreate the settimestampSetRef.current=newSet([...timestampSetRef.current].slice(1));}returnisRe;};
Then in the handler:
usePinch((state)=>{const{ timeStamp }=state;if(isRepeat(timeStamp)){return;}console.log(timeStamp+ ' no more repeats.);
},{target: yourTargetHere});
Yields:
[Log] 890651.0000000001 no more repeats.
[Log] 890655 no more repeats.
[Log] 890663 no more repeats.
[Log] 890672 no more repeats.
andthom
changed the title
usePinch sends duplicate events on Safari
usePinch receives duplicate events on Safari
Sep 7, 2024
Describe the bug
Every usePinch event seems to fire at least twice on Safari.
Example
yields the following on Safari:
and the following on other browsers:
Information:
Checklist:
touch-action: none
to the draggable element.The text was updated successfully, but these errors were encountered: