4bd1a970fd10acefc43fc29ce4932c34.json 13.4 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.createAnimatedEvent=createAnimatedEvent;exports.default=void 0;var _slicedToArray2=_interopRequireDefault(require(\"@babel/runtime/helpers/slicedToArray\"));var _classCallCheck2=_interopRequireDefault(require(\"@babel/runtime/helpers/classCallCheck\"));var _createClass2=_interopRequireDefault(require(\"@babel/runtime/helpers/createClass\"));var _possibleConstructorReturn2=_interopRequireDefault(require(\"@babel/runtime/helpers/possibleConstructorReturn\"));var _getPrototypeOf2=_interopRequireDefault(require(\"@babel/runtime/helpers/getPrototypeOf\"));var _inherits2=_interopRequireDefault(require(\"@babel/runtime/helpers/inherits\"));var _Platform=_interopRequireDefault(require(\"react-native-web/dist/exports/Platform\"));var _findNodeHandle=_interopRequireDefault(require(\"react-native-web/dist/exports/findNodeHandle\"));var _ReanimatedModule=_interopRequireDefault(require(\"../ReanimatedModule\"));var _AnimatedNode2=_interopRequireDefault(require(\"./AnimatedNode\"));var _AnimatedValue=_interopRequireDefault(require(\"./AnimatedValue\"));var _AnimatedAlways=require(\"./AnimatedAlways\");var _invariant=_interopRequireDefault(require(\"fbjs/lib/invariant\"));var _createEventObjectProxyPolyfill=_interopRequireDefault(require(\"./createEventObjectProxyPolyfill\"));function sanitizeArgMapping(argMapping){var eventMappings=[];var alwaysNodes=[];var getNode=function getNode(node){if(_Platform.default.OS==='web'){return node;}return node.__nodeID;};var traverse=function traverse(value,path){if(value instanceof _AnimatedValue.default){eventMappings.push(path.concat(getNode(value)));}else if(typeof value==='object'&&value.__val){eventMappings.push(path.concat(getNode(value.__val)));}else if(typeof value==='function'){var node=new _AnimatedValue.default(0);alwaysNodes.push((0,_AnimatedAlways.createAnimatedAlways)(value(node)));eventMappings.push(path.concat(getNode(node)));}else if(typeof value==='object'){for(var key in value){traverse(value[key],path.concat(key));}}};(0,_invariant.default)(argMapping[0]&&argMapping[0].nativeEvent,'Native driven events only support animated values contained inside `nativeEvent`.');var ev=argMapping[0].nativeEvent;if(typeof ev==='object'){traverse(ev,[]);}else if(typeof ev==='function'){var proxyHandler={get:function get(target,name){if(name==='__isProxy'){return true;}if(!target[name]&&name!=='__val'){target[name]=new Proxy({},proxyHandler);}return target[name];},set:function set(target,prop,value){if(prop==='__val'){target[prop]=value;}}};var proxy=typeof Proxy==='function'?new Proxy({},proxyHandler):(0,_createEventObjectProxyPolyfill.default)();alwaysNodes.push((0,_AnimatedAlways.createAnimatedAlways)(ev(proxy)));traverse(proxy,[]);}return{eventMappings:eventMappings,alwaysNodes:alwaysNodes};}var AnimatedEvent=function(_AnimatedNode){(0,_inherits2.default)(AnimatedEvent,_AnimatedNode);function AnimatedEvent(argMapping){var _this;var config=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};(0,_classCallCheck2.default)(this,AnimatedEvent);var _sanitizeArgMapping=sanitizeArgMapping(argMapping),eventMappings=_sanitizeArgMapping.eventMappings,alwaysNodes=_sanitizeArgMapping.alwaysNodes;_this=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(AnimatedEvent).call(this,{type:'event',argMapping:eventMappings}));_this.__isNative=true;_this._alwaysNodes=alwaysNodes;if(_Platform.default.OS==='web'){_this._argMapping=eventMappings;_this.__getHandler=function(){return function(_ref){var nativeEvent=_ref.nativeEvent;for(var _iterator=_this._argMapping,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol===\"function\"?Symbol.iterator:\"@@iterator\"]();;){var _ref4;if(_isArray){if(_i>=_iterator.length)break;_ref4=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref4=_i.value;}var _ref5=_ref4;var _ref3=(0,_slicedToArray2.default)(_ref5,2);var _key=_ref3[0];var _value=_ref3[1];if(_key in nativeEvent)_value.setValue(nativeEvent[_key]);}};};}return _this;}(0,_createClass2.default)(AnimatedEvent,[{key:\"attachEvent\",value:function attachEvent(viewRef,eventName){for(var i=0;i<this._alwaysNodes.length;i++){this._alwaysNodes[i].__attach();}this.__attach();var viewTag=(0,_findNodeHandle.default)(viewRef);_ReanimatedModule.default.attachEvent(viewTag,eventName,this.__nodeID);}},{key:\"__onEvaluate\",value:function __onEvaluate(){return 0;}},{key:\"detachEvent\",value:function detachEvent(viewRef,eventName){for(var i=0;i<this._alwaysNodes.length;i++){this._alwaysNodes[i].isNativelyInitialized()&&this._alwaysNodes[i].__detach();}var viewTag=(0,_findNodeHandle.default)(viewRef);_ReanimatedModule.default.detachEvent(viewTag,eventName,this.__nodeID);this.__detach();}}]);return AnimatedEvent;}(_AnimatedNode2.default);exports.default=AnimatedEvent;function createAnimatedEvent(argMapping,config){return new AnimatedEvent(argMapping,config);}","map":{"version":3,"sources":["C:/Users/bluej/Desktop/2_2/searchGuide/searchGuide/node_modules/react-native-reanimated/src/core/AnimatedEvent.js"],"names":["sanitizeArgMapping","argMapping","eventMappings","alwaysNodes","getNode","node","Platform","OS","__nodeID","traverse","value","path","InternalAnimatedValue","push","concat","__val","key","nativeEvent","ev","proxyHandler","get","target","name","Proxy","set","prop","proxy","AnimatedEvent","config","type","__isNative","_alwaysNodes","_argMapping","__getHandler","setValue","viewRef","eventName","i","length","__attach","viewTag","ReanimatedModule","attachEvent","isNativelyInitialized","__detach","detachEvent","AnimatedNode","createAnimatedEvent"],"mappings":"q8BACA,6EAEA,qEACA,sEACA,gDAEA,qEACA,wGAEA,QAASA,CAAAA,kBAAT,CAA4BC,UAA5B,CAAwC,CAGtC,GAAMC,CAAAA,aAAa,CAAG,EAAtB,CACA,GAAMC,CAAAA,WAAW,CAAG,EAApB,CAEA,GAAMC,CAAAA,OAAO,CAAG,QAAVA,CAAAA,OAAU,CAAAC,IAAI,CAAI,CACtB,GAAIC,kBAASC,EAAT,GAAgB,KAApB,CAA2B,CACzB,MAAOF,CAAAA,IAAP,CACD,CACD,MAAOA,CAAAA,IAAI,CAACG,QAAZ,CACD,CALD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C,CAAiD,KAAK5B,QAAtD,EACA,KAAKoC,QAAL,GACD,C,2BA3CwCE,sB,gCA8CpC,QAASC,CAAAA,mBAAT,CAA6B9C,UAA7B,CAAyC2B,MAAzC,CAAiD,CACtD,MAAO,IAAID,CAAAA,aAAJ,CAAkB1B,UAAlB,CAA8B2B,MAA9B,CAAP,CACD","sourcesContent":["import { Platform, findNodeHandle } from 'react-native';\nimport ReanimatedModule from '../ReanimatedModule';\n\nimport AnimatedNode from './AnimatedNode';\nimport InternalAnimatedValue from './AnimatedValue';\nimport { createAnimatedAlways } from './AnimatedAlways';\n\nimport invariant from 'fbjs/lib/invariant';\nimport createEventObjectProxyPolyfill from './createEventObjectProxyPolyfill';\n\nfunction sanitizeArgMapping(argMapping) {\n  // Find animated values in `argMapping` and create an array representing their\n  // key path inside the `nativeEvent` object. Ex.: ['contentOffset', 'x'].\n  const eventMappings = [];\n  const alwaysNodes = [];\n\n  const getNode = node => {\n    if (Platform.OS === 'web') {\n      return node;\n    }\n    return node.__nodeID;\n  };\n\n  const traverse = (value, path) => {\n    if (value instanceof InternalAnimatedValue) {\n      eventMappings.push(path.concat(getNode(value)));\n    } else if (typeof value === 'object' && value.__val) {\n      eventMappings.push(path.concat(getNode(value.__val)));\n    } else if (typeof value === 'function') {\n      const node = new InternalAnimatedValue(0);\n      alwaysNodes.push(createAnimatedAlways(value(node)));\n      eventMappings.push(path.concat(getNode(node)));\n    } else if (typeof value === 'object') {\n      for (const key in value) {\n        traverse(value[key], path.concat(key));\n      }\n    }\n  };\n\n  invariant(\n    argMapping[0] && argMapping[0].nativeEvent,\n    'Native driven events only support animated values contained inside `nativeEvent`.'\n  );\n\n  // Assume that the event containing `nativeEvent` is always the first argument.\n  const ev = argMapping[0].nativeEvent;\n  if (typeof ev === 'object') {\n    traverse(ev, []);\n  } else if (typeof ev === 'function') {\n    const proxyHandler = {\n      get: function(target, name) {\n        if (name === '__isProxy') {\n          return true;\n        }\n        if (!target[name] && name !== '__val') {\n          target[name] = new Proxy({}, proxyHandler);\n        }\n        return target[name];\n      },\n      set: function(target, prop, value) {\n        if (prop === '__val') {\n          target[prop] = value;\n        }\n      },\n    };\n\n    const proxy =\n      typeof Proxy === 'function'\n        ? new Proxy({}, proxyHandler)\n        : createEventObjectProxyPolyfill();\n    alwaysNodes.push(createAnimatedAlways(ev(proxy)));\n    traverse(proxy, []);\n  }\n\n  return { eventMappings, alwaysNodes };\n}\n\nexport default class AnimatedEvent extends AnimatedNode {\n  constructor(argMapping, config = {}) {\n    const { eventMappings, alwaysNodes } = sanitizeArgMapping(argMapping);\n    super({ type: 'event', argMapping: eventMappings });\n    this._alwaysNodes = alwaysNodes;\n    if (Platform.OS === 'web') {\n      this._argMapping = eventMappings;\n      this.__getHandler = () => {\n        return ({ nativeEvent }) => {\n          for (const [key, value] of this._argMapping) {\n            if (key in nativeEvent) value.setValue(nativeEvent[key]);\n          }\n        };\n      };\n    }\n  }\n\n  // The below field is a temporary workaround to make AnimatedEvent object be recognized\n  // as Animated.event event callback and therefore filtered out from being send over the\n  // bridge which was causing the object to be frozen in JS.\n  __isNative = true;\n\n  attachEvent(viewRef, eventName) {\n    for (let i = 0; i < this._alwaysNodes.length; i++) {\n      this._alwaysNodes[i].__attach();\n    }\n    this.__attach();\n    const viewTag = findNodeHandle(viewRef);\n    ReanimatedModule.attachEvent(viewTag, eventName, this.__nodeID);\n  }\n\n  __onEvaluate() {\n    return 0;\n  }\n\n  detachEvent(viewRef, eventName) {\n    for (let i = 0; i < this._alwaysNodes.length; i++) {\n      this._alwaysNodes[i].isNativelyInitialized() &&\n        this._alwaysNodes[i].__detach();\n    }\n    const viewTag = findNodeHandle(viewRef);\n    ReanimatedModule.detachEvent(viewTag, eventName, this.__nodeID);\n    this.__detach();\n  }\n}\n\nexport function createAnimatedEvent(argMapping, config) {\n  return new AnimatedEvent(argMapping, config);\n}\n"]},"metadata":{},"sourceType":"script"}