public class EventDispatcher extends java.lang.Object implements LifecycleEventListener
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 = 0xffff000000000000Constructor and Description |
---|
EventDispatcher(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 EventDispatcher(ReactApplicationContext reactContext)
public void dispatchEvent(Event event)
public void dispatchAllEvents()
public void addListener(EventDispatcherListener listener)
public void removeListener(EventDispatcherListener listener)
public void addBatchEventDispatchedListener(BatchEventDispatchedListener listener)
public void removeBatchEventDispatchedListener(BatchEventDispatchedListener listener)
public void onHostResume()
LifecycleEventListener
Activity#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 LifecycleEventListener
public void onHostPause()
LifecycleEventListener
Activity#onPause
. Always called
for the most current activity.onHostPause
in interface LifecycleEventListener
public void onHostDestroy()
LifecycleEventListener
Activity#onDestroy
. Only called
for the last React activity to be destroyed.onHostDestroy
in interface LifecycleEventListener
public void onCatalystInstanceDestroyed()
public void registerEventEmitter(int uiManagerType, RCTEventEmitter eventEmitter)
public void unregisterEventEmitter(int uiManagerType)