You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.8 KiB
1 line
7.8 KiB
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nimport _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\nfunction _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n };\n return _extends.apply(this, arguments);\n}\nimport * as React from 'react';\nimport { useImperativeHandle, useRef } from 'react';\nimport { NativeViewGestureHandler, nativeViewProps } from \"./NativeViewGestureHandler\";\nvar NATIVE_WRAPPER_PROPS_FILTER = [].concat(_toConsumableArray(nativeViewProps), ['onGestureHandlerEvent', 'onGestureHandlerStateChange']);\nexport default function createNativeWrapper(Component) {\n var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var _Component$render;\n var ComponentWrapper = React.forwardRef(function (props, ref) {\n var gestureHandlerProps = Object.keys(props).reduce(function (res, key) {\n var allowedKeys = NATIVE_WRAPPER_PROPS_FILTER;\n if (allowedKeys.includes(key)) {\n res[key] = props[key];\n }\n return res;\n }, _objectSpread({}, config));\n var _ref = useRef();\n var _gestureHandlerRef = useRef();\n useImperativeHandle(ref, function () {\n var node = _gestureHandlerRef.current;\n if (_ref.current && node) {\n _ref.current.handlerTag = node.handlerTag;\n return _ref.current;\n }\n return null;\n }, [_ref, _gestureHandlerRef]);\n return React.createElement(NativeViewGestureHandler, _extends({}, gestureHandlerProps, {\n ref: _gestureHandlerRef\n }), React.createElement(Component, _extends({}, props, {\n ref: _ref\n })));\n });\n ComponentWrapper.displayName = (Component === null || Component === void 0 ? void 0 : Component.displayName) || (Component === null || Component === void 0 ? void 0 : (_Component$render = Component.render) === null || _Component$render === void 0 ? void 0 : _Component$render.name) || typeof Component === 'string' && Component || 'ComponentWrapper';\n return ComponentWrapper;\n}","map":{"version":3,"sources":["createNativeWrapper.tsx"],"names":["React","useImperativeHandle","useRef","NativeViewGestureHandler","nativeViewProps","NATIVE_WRAPPER_PROPS_FILTER","createNativeWrapper","Component","config","ComponentWrapper","forwardRef","props","ref","gestureHandlerProps","keys","reduce","res","key","allowedKeys","includes","_ref","_gestureHandlerRef","node","current","handlerTag","displayName","render","name"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,mBAAT,EAA8BC,MAA9B,QAA4C,OAA5C;AAEA,SACEC,wBADF,EAGEC,eAHF;AAaA,IAAMC,2BAA2B,gCAC5BD,eAD+B,IAElC,uBAFkC,EAGlC,6BAHkC,EAApC;AAMA,eAAe,SAASE,mBAAT,CACbC,SADa,EAGb;EAAA,IADAC,MAA+C,uEAAG,CAAA,CAFrC;EAGb,IAAA,iBAAA;EACA,IAAMC,gBAAgB,GAAG,KAAK,CAACC,UAAN,CAGvB,UAACC,KAAD,EAAQC,GAAR,EAAgB;IAEhB,IAAMC,mBAAmB,GAAG,MAAM,CAACC,IAAP,CAAYH,KAAZ,CAAA,CAAmBI,MAAnB,CAC1B,UAACC,GAAD,EAAMC,GAAN,EAAc;MAEZ,IAAMC,WAA8B,GA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,CAAmBoB,IAFnB,CAAA,IAGC,OAAOpB,SAAP,KAAqB,QAArB,IAAiCA,SAHlC,IAIA,kBALFE;EAOA,OAAOA,gBAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { useImperativeHandle, useRef } from 'react';\n\nimport {\n NativeViewGestureHandler,\n NativeViewGestureHandlerProps,\n nativeViewProps,\n} from './NativeViewGestureHandler';\n\n/*\n * This array should consist of:\n * - All keys in propTypes from NativeGestureHandler\n * (and all keys in GestureHandlerPropTypes)\n * - 'onGestureHandlerEvent'\n * - 'onGestureHandlerStateChange'\n */\nconst NATIVE_WRAPPER_PROPS_FILTER = [\n ...nativeViewProps,\n 'onGestureHandlerEvent',\n 'onGestureHandlerStateChange',\n] as const;\n\nexport default function createNativeWrapper<P>(\n Component: React.ComponentType<P>,\n config: Readonly<NativeViewGestureHandlerProps> = {}\n) {\n const ComponentWrapper = React.forwardRef<\n React.ComponentType<any>,\n P & NativeViewGestureHandlerProps\n >((props, ref) => {\n // filter out props that should be passed to gesture handler wrapper\n const gestureHandlerProps = Object.keys(props).reduce(\n (res, key) => {\n // TS being overly protective with it's types, see https://github.com/microsoft/TypeScript/issues/26255#issuecomment-458013731 for more info\n const allowedKeys: readonly string[] = NATIVE_WRAPPER_PROPS_FILTER;\n if (allowedKeys.includes(key)) {\n // @ts-ignore FIXME(TS)\n res[key] = props[key];\n }\n return res;\n },\n { ...config } // watch out not to modify config\n );\n const _ref = useRef<React.ComponentType<P>>();\n const _gestureHandlerRef = useRef<React.ComponentType<P>>();\n useImperativeHandle(\n ref,\n // @ts-ignore TODO(TS) decide how nulls work in this context\n () => {\n const node = _gestureHandlerRef.current;\n // add handlerTag for relations config\n if (_ref.current && node) {\n // @ts-ignore FIXME(TS) think about createHandler return type\n _ref.current.handlerTag = node.handlerTag;\n return _ref.current;\n }\n return null;\n },\n [_ref, _gestureHandlerRef]\n );\n return (\n <NativeViewGestureHandler\n {...gestureHandlerProps}\n // @ts-ignore TODO(TS)\n ref={_gestureHandlerRef}>\n <Component {...props} ref={_ref} />\n </NativeViewGestureHandler>\n );\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n ComponentWrapper.displayName =\n Component?.displayName ||\n // @ts-ignore if render doesn't exist it will return undefined and go further\n Component?.render?.name ||\n (typeof Component === 'string' && Component) ||\n 'ComponentWrapper';\n\n return ComponentWrapper;\n}\n"]},"metadata":{},"sourceType":"module"} |