//@ts-ignore import Pressability from 'react-native/Libraries/Pressability/Pressability'; import { parseTouchEvent, trackPressability } from '../click/trackClick'; const InjectSign = '__$bd_inject_onpress$__'; function injectOnpress(pressabilityConfig: any) { if (!pressabilityConfig.onPress) { return; } if (pressabilityConfig[InjectSign]) { return; } pressabilityConfig.onPress = new Proxy(pressabilityConfig.onPress, { apply: (target, thisArgument, argumentsList) => { const event = argumentsList[0]; const touchNode = event._targetInst; // console.info(Object.keys(event._targetInst)); try { parseTouchEvent(event, (touch) => { try { if (touch) { trackPressability(touchNode, touch); } } catch (e: any) { console.warn(e.message); } Reflect.apply(target, thisArgument, argumentsList); }); } catch (e: any) { Reflect.apply(target, thisArgument, argumentsList); console.warn(e.message); } }, }); pressabilityConfig[InjectSign] = 1; } export default function injectPressability() { const proto = Pressability.prototype; proto.configure = new Proxy(proto.configure, { apply(target, thisArgument, argumentsList) { const pressabilityConfig = argumentsList[0]; try { injectOnpress(pressabilityConfig); } catch (e: any) { console.warn(e.message); } return Reflect.apply(target, thisArgument, argumentsList); }, }); }