nuclearpasta / react-native-drax

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

Receivers are non-deterministic #175

Open ofersadgat opened 2 months ago

ofersadgat commented 2 months ago

findMonitorsAndReceiverInRegistry will look through the registry viewIds and return the last receiver which matches. the problem here is that this assumes that the order of receiver ids in the registry viewIds is bottom to top. this is not always the case when you have various receivers re-rendering for various reasons. this resulted in a non-deterministic receiver being called on drop instead of the top most one. in order to fix this, I added a resolution algorithm in the case that multiple receivers overlap the target point. the resolution algorithm solves the issue first by looking through the parent tree and removing all parents. while I believe this should be enough, for safety, I added an additional fallback measure which chooses the receiver with the smallest area as generally things on top should be smaller than things on bottom.

lafiosca commented 2 months ago

This is a great find and I appreciate the work and PR. I have not been actively maintaining this library for a long time, and unfortunately there is no current maintainer. Additionally, I am in the process of winding down Nuclear Pasta and have been considering what I should do about this library. I will take a look and see if I can merge this and publish a new version, but I want to set expectations that it might take me a while to get to it.

ofersadgat commented 1 month ago

@LunatiqueCoder sorry about that, I'll fix it when the rest of the MR gets reviewed.

LunatiqueCoder commented 1 month ago

do you have a reproduction example to test the changes?