UNPKG

react-native-web-internals

Version:

React Native for Web

45 lines (44 loc) 1.62 kB
import canUseDOM from "../canUseDOM.native.js"; var emptyFunction = function () {}; function supportsPassiveEvents() { var supported = !1; if (canUseDOM) try { var options = {}; Object.defineProperty(options, "passive", { get() { return supported = !0, !1; } }), window.addEventListener("test", null, options), window.removeEventListener("test", null, options); } catch {} return supported; } var canUsePassiveEvents = supportsPassiveEvents(); function getOptions(options) { return options == null ? !1 : canUsePassiveEvents ? options : !!options.capture; } function isPropagationStopped() { return this.cancelBubble; } function isDefaultPrevented() { return this.defaultPrevented; } function normalizeEvent(event) { return event.nativeEvent = event, event.persist = emptyFunction, event.isDefaultPrevented = isDefaultPrevented, event.isPropagationStopped = isPropagationStopped, event; } function createEventHandle(type, options) { var opts = getOptions(options); return function (target, listener) { if (target == null || typeof target.addEventListener != "function") throw new Error("createEventHandle: called on an invalid target."); var element = target; if (listener != null) { var compatListener = function (e) { return listener(normalizeEvent(e)); }; return element.addEventListener(type, compatListener, opts), function () { element?.removeEventListener(type, compatListener, opts); }; } else return emptyFunction; }; } export { createEventHandle as default }; //# sourceMappingURL=index.native.js.map