-
public abstract class Event<T extends Event>
A UI event that can be dispatched to JS.
For dispatching events
{@code getEventData}
should be used. Once event object is passed to the EventDispatched it should no longer be used as EventDispatcher may decide to recycle that object (by calling dispose).If you need advanced customizations and overriding only
{@code getEventData}
doesn't work for you, you must override both{@code dispatch}
and{@code dispatchModern}
. Both of these will be deleted in the distant future and it is highly recommended to use only{@code getEventData}
.Old, pre-Fabric Events only used viewTag as the identifier, but Fabric needs surfaceId as well as viewTag. You may use
{@code UIManagerHelper.getSurfaceId}
on a Fabric-managed View to get the surfaceId. Fabric will work without surfaceId - making{@code Event}
backwards-compatible - but Events without SurfaceId are slightly slower to propagate.
-
-
Method Summary
Modifier and Type Method Description final int
getViewTag()
final int
getSurfaceId()
final long
getTimestampMs()
boolean
canCoalesce()
T
coalesce(T otherEvent)
Given two events, coalesce them into a single event that will be sent to JS instead of twoseparate events. short
getCoalescingKey()
int
getUniqueID()
void
onDispose()
Called when the EventDispatcher is done with an event, either because it was dispatched orbecause it was coalesced with another Event. final int
getUIManagerType()
abstract String
getEventName()
void
dispatch(RCTEventEmitter rctEventEmitter)
Dispatch this event to JS using the given event emitter. void
dispatchModern(RCTModernEventEmitter rctEventEmitter)
Dispatch this event to JS using a V2 EventEmitter. -
-
Method Detail
-
getViewTag
final int getViewTag()
-
getSurfaceId
final int getSurfaceId()
-
getTimestampMs
final long getTimestampMs()
-
canCoalesce
boolean canCoalesce()
-
coalesce
T coalesce(T otherEvent)
Given two events, coalesce them into a single event that will be sent to JS instead of twoseparate events. By default, just chooses the one the is more recent, or
{@code this}
iftimestamps are the same.Two events will only ever try to be coalesced if they have the same event name, view id, andcoalescing key.
-
getCoalescingKey
short getCoalescingKey()
-
getUniqueID
int getUniqueID()
-
onDispose
void onDispose()
Called when the EventDispatcher is done with an event, either because it was dispatched orbecause it was coalesced with another Event.
-
getUIManagerType
final int getUIManagerType()
-
getEventName
abstract String getEventName()
-
dispatch
@Deprecated() void dispatch(RCTEventEmitter rctEventEmitter)
Dispatch this event to JS using the given event emitter. Compatible with old and new renderer.Instead of using this or dispatchModern, it is recommended that you simply override`getEventData`.
-
dispatchModern
@Deprecated() void dispatchModern(RCTModernEventEmitter rctEventEmitter)
Dispatch this event to JS using a V2 EventEmitter. If surfaceId is not -1 and `getEventData` isnon-null, this will use the RCTModernEventEmitter API. Otherwise, it falls back to theold-style dispatch function. For Event classes that need to do something different, this methodcan always be overridden entirely, but it is not recommended.
This method additionally allows C++ to coalesce events and detect continuous ones forconcurrent mode (Fabric only).
-
-
-
-