## Summary Set up the experiment to migrate event dispatching in the React Native renderer to be based on the native EventTarget API. Behind the `enableNativeEventTargetEventDispatching` flag, events are dispatched through `dispatchTrustedEvent` instead of the legacy plugin system. Regular event handler props are NOT registered via addEventListener at commit time. Instead, a hook on EventTarget (`EVENT_TARGET_GET_DECLARATIVE_LISTENER_KEY`) extracts handlers from `canonical.currentProps` at dispatch time, shifting cost from every render to only when events fire. The hook is overridden in ReactNativeElement to look up the prop name via a reverse mapping from event names (built lazily from the view config registry). Responder events bypass EventTarget entirely. `negotiateResponder` walks the fiber tree directly (capture then bubble phase), calling handlers from `canonical.currentProps` and checking return values inline. Lifecycle events (`responderGrant`, `responderMove`, etc.) call handlers directly from props and inspect return values — `onResponderGrant` returning `true` blocks native responder, `onResponderTerminationRequest` returning `false` refuses termination. This eliminates all commit-time cost for responder events (no wrappers, no addEventListener, no `responderWrappers` on canonical). ## How did you test this change? Flow Tested e2e in RN using Fantom tests (that will land after this).
24 lines
934 B
JavaScript
24 lines
934 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
// These globals are set by React Native (e.g. in setUpDOM.js, setUpTimers.js)
|
|
// and provide access to RN's feature flags. We use global functions because we
|
|
// don't have another mechanism to pass feature flags from RN to React in OSS.
|
|
// Values are lazily evaluated and cached on first access.
|
|
|
|
let _enableNativeEventTargetEventDispatching: boolean | null = null;
|
|
export function enableNativeEventTargetEventDispatching(): boolean {
|
|
if (_enableNativeEventTargetEventDispatching == null) {
|
|
_enableNativeEventTargetEventDispatching =
|
|
typeof RN$isNativeEventTargetEventDispatchingEnabled === 'function' &&
|
|
RN$isNativeEventTargetEventDispatchingEnabled();
|
|
}
|
|
return _enableNativeEventTargetEventDispatching;
|
|
}
|