public class EventDispatcherImpl extends java.lang.Object implements EventDispatcher, LifecycleEventListener
To use it, create a subclass of Event and call dispatchEvent(Event) 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
| Constructor and Description |
|---|
EventDispatcherImpl(ReactApplicationContext reactContext) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBatchEventDispatchedListener(BatchEventDispatchedListener listener) |
void |
addListener(EventDispatcherListener listener)
Add a listener to this EventDispatcher.
|
void |
dispatchAllEvents() |
void |
dispatchEvent(Event event)
Sends the given Event to JS, coalescing eligible events if JS is backed up.
|
void |
onCatalystInstanceDestroyed() |
void |
onHostDestroy()
Called when host activity receives destroy event (e.g.
|
void |
onHostPause()
Called when host activity receives pause event (e.g.
|
void |
onHostResume()
Called either when the host activity receives a resume event (e.g.
|
void |
registerEventEmitter(int uiManagerType,
RCTEventEmitter eventEmitter) |
void |
removeBatchEventDispatchedListener(BatchEventDispatchedListener listener) |
void |
removeListener(EventDispatcherListener listener)
Remove a listener from this EventDispatcher.
|
void |
unregisterEventEmitter(int uiManagerType) |
public EventDispatcherImpl(ReactApplicationContext reactContext)
public void dispatchEvent(Event event)
dispatchEvent in interface EventDispatcherpublic void dispatchAllEvents()
dispatchAllEvents in interface EventDispatcherpublic void addListener(EventDispatcherListener listener)
addListener in interface EventDispatcherpublic void removeListener(EventDispatcherListener listener)
removeListener in interface EventDispatcherpublic void addBatchEventDispatchedListener(BatchEventDispatchedListener listener)
addBatchEventDispatchedListener in interface EventDispatcherpublic void removeBatchEventDispatchedListener(BatchEventDispatchedListener listener)
removeBatchEventDispatchedListener in interface EventDispatcherpublic void onHostResume()
LifecycleEventListenerActivity#onResume or
if the native module that implements this is initialized while the host activity is already
resumed. Always called for the most current activity.onHostResume in interface LifecycleEventListenerpublic void onHostPause()
LifecycleEventListenerActivity#onPause. Always called
for the most current activity.onHostPause in interface LifecycleEventListenerpublic void onHostDestroy()
LifecycleEventListenerActivity#onDestroy. Only called
for the last React activity to be destroyed.onHostDestroy in interface LifecycleEventListenerpublic void onCatalystInstanceDestroyed()
onCatalystInstanceDestroyed in interface EventDispatcherpublic void registerEventEmitter(int uiManagerType,
RCTEventEmitter eventEmitter)
registerEventEmitter in interface EventDispatcherpublic void unregisterEventEmitter(int uiManagerType)
unregisterEventEmitter in interface EventDispatcher