-
-
Notifications
You must be signed in to change notification settings - Fork 955
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
base: main
Are you sure you want to change the base?
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! |
EDITED 22/05/21
Motivation #928
PanGestureHandler
-> usingPanGestureHandler
requires a lot of boilerplate to get it to function as a synthetic drag and drop handler (I've tried it rn-drag-drop).FlatList
is a KILLER).react-native-gesture-handler
aims 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:
DragGestureHandler
andDropGestureHandler
both of them extendPanGestureHandler
.I have made adaptions mainly to
GestureHandlerOrchestrator
in the android native code and added examples underDrag & Drop
andDrag & 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
handlerTag
to 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.
PanGestureHandler
super class ofDragGestureHandler
receives events. It is in charge of moving fromState.UNDETERMINED
toState.BEGAN
andState.ACTIVE
based on it's own logic.Once active,
DragGestureHandler
begins dragging.From this point on the
GestureHandlerOrchestrator
receives aDragEvent
which is first adapted to aMotionEvent
and delivered to all handlers. This is done to activateDropGestureHandlers
(DropGestureHandler
is the same asDragGestureHandler
in terms ofPanGestureHandler
responsibilities), run simultaneous handlers and cancel the rest.Then the
DragEvent
is delivered to all handlers,DropGestureHandlers
first, then the rest.Extracting
DropGestureHandlers
is done for each event to obtain the top most handler.If
DropGestureHandlers
are extracted the top most will be activated notifying the other drag/drop handlers with an appropriateaction
.Multi Window
Android supports multi window.
The
AndroidManifest.xml
file 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
DragGestureHandler
unaware of interactions withDropGestureHandlers
. So, I've added a small broadcasting mechanism that broadcasts changes of the dragaction
to the source app.To test this I suggest running both
AndroidNativeExample
andExample
side by side.Simultaneous Handlers
There is a caveat regarding simultaneous handlers. A drag event (on android) has only one pointer so simultaneous handling with
RotationGestureHandler
orPinchGestureHandler
won't work unfortunately.Passing
DragGestureHandlers
before the event begins will join them to the drag event and add them to the drag shadow. See example.Props
number | number[] | null
, if aDragGestureHandler
and aDropGestureHandler
share one type they can interact.DragGestureHandler props
DropGestureHandler
on drop via gesture event.There are several options here, all listed in
react-native-gesture-handler.d.ts
dragMode
- handles the visibilty ofDragGestureHandler
while draggingmove
move-restore
- after drop occurs, restores visibility to the DragGestureHandler's viewcopy
none
shadow
=component | element | tag | null
to render view while draggingmerged asshadowEnabled
dragMode='none'
shadowConfig
- control position, opacity, margin, etc.Drag shadow can update during a drag only for
nougat
and higher.Events
Extending
PanGestureHandler
event.#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!