react-native-pinchable icon indicating copy to clipboard operation
react-native-pinchable copied to clipboard

Pinchable inside a pressable component

Open pierroo opened this issue 2 years ago • 3 comments

Library works awesome: great job!

One minor inconvenience is that if the pinchable component (image) is inside a parent pressable item, upon leaving the pinched image to zoom, it will trigger the pressable component behind.

is there any way that when the pinch is triggered, it disables any "background" event?

pierroo avatar Nov 30 '22 17:11 pierroo

Any answer about that?

renanbronchart avatar Oct 30 '23 15:10 renanbronchart

We need solution for this issue very much. Anyone know how to mention any related people about this issue?

jeffinhk avatar May 23 '24 18:05 jeffinhk

I use this custom component. If the pinchable action is more than 160 milliseconds, it will avoid triggering the press.

import React from 'react'
import { Pressable } from 'react-native'

const PressableDelayed: React.FC = ({ onPress, children, ...props }) => {
  const timer = React.useRef(0)

  return (
    <Pressable
      onPressIn={() => {
        timer.current = new Date().getTime()
      }}
      onPress={() => {
        if (new Date().getTime() - timer.current > 160) return
        if (onPress) onPress()
      }}
      {...props}
    >
      {children}
    </Pressable>
  )
}

export default PressableDelayed
    <Pinchable>
      <PressableDelayed onPress={...}>
        ...stuff
      </PressableDelayed>
    </Pinchable>

In my use case, the pinchable is the parent but I would guess it works in the reverse as well.

jslok avatar Jun 26 '24 01:06 jslok