UNPKG

react-native-tvos

Version:
91 lines (78 loc) 2.32 kB
/** * 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 strict * @format */ import Event, {type EventInit} from '../../webapis/dom/events/Event'; // flowlint unsafe-getters-setters:off export type DispatchConfig = | Readonly<{registrationName: string, dependencies?: ReadonlyArray<string>}> | Readonly<{ phasedRegistrationNames: Readonly<{ bubbled: string, captured: string, skipBubbling?: ?boolean, }>, dependencies?: ReadonlyArray<string>, }>; /** * A bridge event class that extends the W3C Event interface and carries * the native event payload. This is used as a compatibility layer during * the migration from the legacy SyntheticEvent system to EventTarget-based * dispatching. */ export default class LegacySyntheticEvent extends Event { _nativeEvent: {[string]: unknown}; _propagationStopped: boolean; _dispatchConfig: DispatchConfig | null; constructor( type: string, options: EventInit, nativeEvent: {[string]: unknown}, dispatchConfig?: ?DispatchConfig, ) { super(type, options); this._nativeEvent = nativeEvent; this._propagationStopped = false; this._dispatchConfig = dispatchConfig ?? null; } get nativeEvent(): {[string]: unknown} { return this._nativeEvent; } get dispatchConfig(): DispatchConfig | null { return this._dispatchConfig; } stopPropagation(): void { super.stopPropagation(); this._propagationStopped = true; } stopImmediatePropagation(): void { super.stopImmediatePropagation(); this._propagationStopped = true; } /** * No-op for backward compatibility. The legacy SyntheticEvent system * used pooling which required calling persist() to keep the event. * With EventTarget-based dispatching, events are never pooled. */ persist(): void { // No-op } /** * Backward-compatible wrapper for `defaultPrevented`. */ isDefaultPrevented(): boolean { return this.defaultPrevented; } /** * Backward-compatible wrapper. Returns true if stopPropagation() * has been called. */ isPropagationStopped(): boolean { return this._propagationStopped; } }