-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Drag Gesture Handler #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drag Gesture Handler #963
Conversation
fix metro package collisions for Example app. use yarn to install dependencies
update from master
update fork from origin
organize code add cancel handler check
Was caused because view was hidden before the drag events began to propagate causing a situation that if a drag has started but no events would be emitted because the finger stopped touching the screen the view would remain invisible. This was fixed by: Moving `setVisibility(false)` to `onHandle` instead of `startDragging`. Reinstating `onHandle(MotionEvent event)` to the super pan handler so it can handle this exact case of `ACTION_UP` fired after `startDragging` and propagate state changes
revert ACTION_DRAG_CANCELLED approach finalizes 8b0e840
dosn't seem to yield the desired effect... but is logially correct
…t to unmount We want to avoid flickering in case the handler has been reset after being cancelled because it's view is being removed from the tree. We don't want the view reappearing just to get removed a few frames later, so we use postDelayed to reset visibility after react has unmounted the view . ```
|
fixed a bunch of edge case bugs |
update drag shadow after joining drag handler cancellation resetHandlerViewState is now called once handler is finished, not reset, which is the correct approach. Hope this doesn't intoduce bugs.
add test cases for handler cancellation edge cases
cancel remaining handlers that originated from the MotionEvent that aren't related to drag event and are probably configured as simultaneous/waitFor handlers on drag handlers
|
I think android is ready for roll out |
|
Would this support web too? |
@nandorojo Why not? It can wrap around |
|
That would be awesome |
|
@ShaMan123 would it be possible to move this PR into a standalone npm package, which uses gesture handler as a peer dependency? That way, you could get community support and testing to help get this merged. It doesn't seem likely that this will get merged as-is right now, but I'd love to get to use it in my app. I think making it a separate package (like What do you think? |
|
I think it isn't feasible.
The code can't be separated from the core. And can't be patched together.
There is logic that changed.
You could PR my fork and I'll merge it.
I think this is worth working on to support ios.
בתאריך יום ד׳, 19 במאי 2021, 15:31, מאת Fernando Rojo <
***@***.***>:
… @ShaMan123 <https://github.com/ShaMan123> would it be possible to move
this PR into a standalone npm package, which uses gesture handler as a peer
dependency? That way, you could get community support and testing to help
get this merged.
It doesn't seem likely that this will get merged as-is right now, but I'd
love to get to use this. I think making it a separate package (like
native-dnd) would be awesome.
What do you think?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#963 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIGAW4OW25HSYEEDKHAFZFDTOOVTDANCNFSM4KTI6WOQ>
.
|
|
I see. How far along is it? Is it all working for you? |
|
Android works completely.
|
|
+1 Let's get this merged in! |
|
With the number of changes that happened in the repository since this PR has been opened, I don't think this is mergeable anymore. |
EDITED 22/05/21
Motivation #928
PanGestureHandler-> usingPanGestureHandlerrequires a lot of boilerplate to get it to function as a synthetic drag and drop handler (I've tried it rn-drag-drop).FlatListis a KILLER).react-native-gesture-handleraims to be a plug and play library, this is why I think drag and drop gesture handling is essential.Changes
I've added 2 new handlers:
DragGestureHandlerandDropGestureHandlerboth of them extendPanGestureHandler.I have made adaptions mainly to
GestureHandlerOrchestratorin the android native code and added examples underDrag & DropandDrag & Drop in FlatList.In addition I've revived the native android example, this was done by adjusting the gesture handler registry and mocking a root view.
The only thing out of scope is this fix, which fixes passing down the wrong
handlerTagto native making relations config wrong forNativeViewGestureHandler.https://github.com/software-mansion/react-native-gesture-handler/pull/963/files#diff-6eb54a5e8a566ff2be948cdfe0abb5f4
Logic
Gesture handling is in progress.
PanGestureHandlersuper class ofDragGestureHandlerreceives events. It is in charge of moving fromState.UNDETERMINEDtoState.BEGANandState.ACTIVEbased on it's own logic.Once active,
DragGestureHandlerbegins dragging.From this point on the
GestureHandlerOrchestratorreceives aDragEventwhich is first adapted to aMotionEventand delivered to all handlers. This is done to activateDropGestureHandlers(DropGestureHandleris the same asDragGestureHandlerin terms ofPanGestureHandlerresponsibilities), run simultaneous handlers and cancel the rest.Then the
DragEventis delivered to all handlers,DropGestureHandlersfirst, then the rest.Extracting
DropGestureHandlersis done for each event to obtain the top most handler.If
DropGestureHandlersare extracted the top most will be activated notifying the other drag/drop handlers with an appropriateaction.Multi Window
Android supports multi window.
The
AndroidManifest.xmlfile needs to be edited to get this working.To persist the same behavior I had to add some logic to bridge the framework not dispatching drag events back to the app that started the drag gesture, leaving
DragGestureHandlerunaware of interactions withDropGestureHandlers. So, I've added a small broadcasting mechanism that broadcasts changes of the dragactionto the source app.To test this I suggest running both
AndroidNativeExampleandExampleside by side.Simultaneous Handlers
There is a caveat regarding simultaneous handlers. A drag event (on android) has only one pointer so simultaneous handling with
RotationGestureHandlerorPinchGestureHandlerwon't work unfortunately.Passing
DragGestureHandlersbefore the event begins will join them to the drag event and add them to the drag shadow. See example.Props
number | number[] | null, if aDragGestureHandlerand aDropGestureHandlershare one type they can interact.DragGestureHandler props
DropGestureHandleron drop via gesture event.There are several options here, all listed in
react-native-gesture-handler.d.tsdragMode- handles the visibilty ofDragGestureHandlerwhile draggingmovemove-restore- after drop occurs, restores visibility to the DragGestureHandler's viewcopynoneshadow=component | element | tag | nullto render view while draggingmerged asshadowEnableddragMode='none'shadowConfig- control position, opacity, margin, etc.Drag shadow can update during a drag only for
nougatand higher.Events
Extending
PanGestureHandlerevent.#963 (comment)
I believe iOS will be much easier to implement.
Please consider adding this to the road map. Drag gesture handling is the missing piece of RNGH!