-
- All Implemented Interfaces:
-
com.facebook.react.bridge.LifecycleEventListener
,com.facebook.react.uimanager.events.EventDispatcher
public class LockFreeEventDispatcherImpl implements EventDispatcher, LifecycleEventListener
Class responsible for dispatching UI events to JS. The main purpose of this class is to act as an intermediary between UI code generating events and JS, making sure we don't send more events than JS can process.
To use it, create a subclass of Event and call dispatchEvent whenever there's a UI event to dispatch.
This class works by installing a Choreographer frame callback on the main thread. This callback then enqueues a runnable on the JS thread (if one is not already pending) that is responsible for actually dispatch events to JS. This implementation depends on the properties that 1) FrameCallbacks run after UI events have been processed in Choreographer.java 2) when we enqueue a runnable on the JS queue thread, it won't be called until after any previously enqueued JS jobs have finished processing
If JS is taking a long time processing events, then the UI events generated on the UI thread can be coalesced into fewer events so that when the runnable runs, we don't overload JS with a ton of events and make it get even farther behind.
Ideally, we don't need this and JS is fast enough to process all the events each frame, but bad things happen, including load on CPUs from the system, and we should handle this case well.
== Event Cookies ==
An event cookie is made up of the event type id, view tag, and a custom coalescing key. Only Events that have the same cookie can be coalesced.
Event Cookie Composition: VIEW_TAG_MASK = 0x00000000ffffffff EVENT_TYPE_ID_MASK = 0x0000ffff00000000 COALESCING_KEY_MASK = 0xffff000000000000
This is a copy of EventDispatcherImpl, meant only to remove locking and synchronization.
-
-
Constructor Summary
Constructors Constructor Description LockFreeEventDispatcherImpl(ReactApplicationContext reactContext)
-
Method Summary
Modifier and Type Method Description void
dispatchEvent(Event event)
Sends the given Event to C++, where it will be flushed to JS ASAP. void
dispatchAllEvents()
void
addListener(EventDispatcherListener listener)
Add a listener to this EventDispatcher. void
removeListener(EventDispatcherListener listener)
Remove a listener from this EventDispatcher. void
addBatchEventDispatchedListener(BatchEventDispatchedListener listener)
void
removeBatchEventDispatchedListener(BatchEventDispatchedListener listener)
void
onHostResume()
Called either when the host activity receives a resume event (e.g. void
onHostPause()
Called when host activity receives pause event (e.g. void
onHostDestroy()
Called when host activity receives destroy event (e.g. void
onCatalystInstanceDestroyed()
void
registerEventEmitter(int uiManagerType, RCTEventEmitter eventEmitter)
void
registerEventEmitter(int uiManagerType, RCTModernEventEmitter eventEmitter)
void
unregisterEventEmitter(int uiManagerType)
-
-
Constructor Detail
-
LockFreeEventDispatcherImpl
LockFreeEventDispatcherImpl(ReactApplicationContext reactContext)
-
-
Method Detail
-
dispatchEvent
void dispatchEvent(Event event)
Sends the given Event to C++, where it will be flushed to JS ASAP.
-
dispatchAllEvents
void dispatchAllEvents()
-
addListener
void addListener(EventDispatcherListener listener)
Add a listener to this EventDispatcher.
-
removeListener
void removeListener(EventDispatcherListener listener)
Remove a listener from this EventDispatcher.
-
addBatchEventDispatchedListener
void addBatchEventDispatchedListener(BatchEventDispatchedListener listener)
-
removeBatchEventDispatchedListener
void removeBatchEventDispatchedListener(BatchEventDispatchedListener listener)
-
onHostResume
void onHostResume()
Called either when the host activity receives a resume event (e.g. onResume orif the native module that implements this is initialized while the host activity is alreadyresumed. Always called for the most current activity.
-
onHostPause
void onHostPause()
Called when host activity receives pause event (e.g. onPause. Always calledfor the most current activity.
-
onHostDestroy
void onHostDestroy()
Called when host activity receives destroy event (e.g. onDestroy. Only calledfor the last React activity to be destroyed.
-
onCatalystInstanceDestroyed
void onCatalystInstanceDestroyed()
-
registerEventEmitter
void registerEventEmitter(int uiManagerType, RCTEventEmitter eventEmitter)
-
registerEventEmitter
void registerEventEmitter(int uiManagerType, RCTModernEventEmitter eventEmitter)
-
unregisterEventEmitter
void unregisterEventEmitter(int uiManagerType)
-
-
-
-