-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix event handling #1319
Fix event handling #1319
Conversation
String key = viewTag + eventName; | ||
|
||
shouldSaveEvent |= (mCustomEventHandler != null && mNativeProxy.isAnyHandlerWaitingForEvent(key)); | ||
mEventQueue.offer(new CopiedEvent(event)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from #1149
Maybe we could also pool CopiedEvent objects same way we have pools of other events. In this case this should be rather efficient as there typically won't be more than 2-3 events in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a need for a CopiedEvent pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using the pool will strain GC, event objects will be created and removed frequently if events will be coming from other source than the UI thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't make sense for me because we still have to create and remove events' payloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe @kmagiera will chime in since he suggested this change in the original PR.
Copied from #1149
Description
Previously, we were handling dispatched events like so:
Event handling in RN works by utilizing
EventDispatcher.dispatchEvent(event)
whichonEventDispatch
callback on any registered listenerevent
to internal event queueThis approach introduced timing issues - RN's
EventDispatcher
dispatches events on JS thread and Reanimated handles events on UI thread. There's a possibility thatEventDispatcher
will dispose event (possibly destroying it's state inonDispose()
) before Reanimated would have chance to handle it.This was found after investigating pretty popular crash in react-native-gesture-handler.
HOW
The pull-request adds another method
isAnyHandlerWaitingForEvent
to NativeProxy API which lets us check if an event is important (there is workletHandler listening for the event) or not. The rest part of the pr is very similar to Jakub's pr. However, there are some differences. Instead of saving copied event Object, we save: tag, eventName, and payload in the new classCopiedEvent
.