nuclearpasta / react-native-drax

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

Android drag offset issues #58

Open lafiosca opened 4 years ago

lafiosca commented 4 years ago

Now that react-native-drax-example has been updated to the latest react-native, react-navigation, react-native-safe-area-context, and react-native-gesture-handler, I'm experiencing a few functionality problems with drags on the Android build.

On a physical Galaxy S7 Edge, everything seems to work as expected until I rotate the phone into a different orientation. The display automatically rotates, but the drag offsets are wrong, to the point of almost completely breaking the Knight Moves example.

On an emulated Pixel 3a, the drag offsets are wrong when the Color Drag/Drop screen first loads. Specifically, when grabbing a color block, it hovers what appears to be roughly one Android status bar height vertically above where the gesture is touching. The other examples work as expected. Then when I rotate the emulated device, it doesn't automatically reorient the app, but a little software rotation button shows up, as seen in the upper-right corner of this screenshot:

image

When I click this, the app reorients into landscape, and all offsets work fine. Then if I rotate back into portrait and click the button again, everything behaves as it should. This implies to me that during the initialization of the app, Drax is somehow calibrating its base coordinates in the wrong place (perhaps not accounting for status bar), but that when the orientation change handler recalibrates, it's fine. As with all Android issues, I dread trying to determine whether this is specific to only certain devices.

lafiosca commented 3 years ago

On a new physical Nokia 3.4 running Android 10, with RN 0.63.3 and the latest drax, everything seems mostly ok. There is still the slight vertical offset problem with the colors when the app is first loaded. Rotating and rotating back fixes it, which again implies a potential race condition with the layout measurements. Generally the positions work fine after rotating to landscape, but at least once I was able to get the offsets to be WAY off. It's not easy to reproduce on demand however.

I have been thinking that one possible approach would be to have Drax periodically perform some kind of remeasurement. This is a very ham-handed solution, but it might help in the most general "weird stuff happening" cases. Another option could be to just do a second delayed measurement after the initial one, in case.