nuclearpasta / react-native-drax

A drag-and-drop system for React Native
MIT License
554 stars 68 forks source link

Is there an onPress event? #76

Open alvaro1728 opened 3 years ago

alvaro1728 commented 3 years ago

Hi, I want to detect when the user just taps on the DraxView. I would interpret that as him wanting to edit the contents, not drag it around. That's typically done via an onPress event handler. Is there something similar here?

Thanks, Alvaro

lafiosca commented 3 years ago

Hi Alvaro,

I'll start this reply with my standard apology for the state of maintenance of this library right now. Personal circumstances have not afforded me the time to do any deep work on Drax for a while, and I am not fresh on the code. I have a Drax logic documentation project in progress but presently on hold. The goal with that is to make it easier for myself and others to maintain the library without accidentally breaking or changing functionality. I do however keep an eye on the issues and try to answer things off the top of my head if I am able.

Unfortunately, this sounds to me like a feature request and not something currently provided by the library. The main DraxView gesture logic is implemented with a LongPressGestureHandler as seen here:

https://github.com/nuclearpasta/react-native-drax/blob/051295857fd840e38eb79ded9edabee31f8d7178/src/DraxView.tsx#L620-L637

I believe it would require us to add a TapGestureHandler and to ensure that the two would interoperate without clobbering each other, but that might be easier said than done. Getting the gesture handler logic functioning was always fraught and involved various workarounds. I have not worked on this logic or experimented with react-native-gesture-handler in quite a while though, so I am not sure what the latest state of that library is or whether things might go more smoothly now.

alvaro1728 commented 3 years ago

Hi Joe,

Thanks for your thorough reply. I hope your circumstances change and you're able to devote more time to this great library, which I'm putting to use as we speak. A Tap (or Press) GestureHandler sounds like the right approach. In the mean time, I'm going to find some sort of workaround. One that comes to mind is storing the current time in onDragStart and checking it against the current time in onDragEnd. If the difference is smaller than say 100 (ms), then I can treat it as a tap.

Thanks again, Alvaro

lafiosca commented 3 years ago

You'll need to lower the longPressDelay for that workaround, which may give you trouble if it's too low. Hope you can make it work!

alvaro1728 commented 3 years ago

In case anyone's looking for a working solution to this, here's what I did. In my case, I have my DragViews already over a receiver DraxView so I checked for drag activity using the onDragStart, onDragOver, and onDragDrop handlers. I used the DraxViews payload to keep track of whether it's being dragged. So here it is:

<DraxView 
      payload={someObject}
      onDragStart={() => someObject.dragged = false}
      onDragOver={event => {
        if (event.dragTranslation.x || event.dragTranslation.y) {
          someObject.dragged = true;
        }
      }}
      onDragDrop={event => {
        if (!someObject.dragged) {
          onEdit(someObject);
        }
      }}>
...
</DraxView>

Cheers, Alvaro

lafiosca commented 3 years ago

Thanks, Alvaro. I'm going to keep this issue open as a feature request for the future.