EventDispatcherImpl

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

Constructors

Link copied to clipboard
constructor(reactContext: ReactApplicationContext)

Functions

Link copied to clipboard
Add a listener to this EventDispatcher.
Link copied to clipboard
Link copied to clipboard
open fun dispatchEvent(event: Event)
Sends the given Event to JS, coalescing eligible events if JS is backed up.
Link copied to clipboard
Link copied to clipboard
open fun onHostDestroy()
Called when host activity receives destroy event (e.g.
Link copied to clipboard
open fun onHostPause()
Called when host activity receives pause event (e.g.
Link copied to clipboard
open fun onHostResume()
Called either when the host activity receives a resume event (e.g.
Link copied to clipboard
Remove a listener from this EventDispatcher.