import { parseTouchEvent, trackClick } from '../click/trackClick'; const InjectSign = '__$bd_inject_props_onclick$__'; const InjectEventSign = '__$bd_inject_original_event$__'; export function injectPropsClick(stateNode: any) { if (!stateNode) { return; } const props = stateNode.props; if (!props.onClick) { return; } stateNode.getWxAppEvent = new Proxy(stateNode.getWxAppEvent, { apply: (target, thisArgument, argumentsList) => { const originalEvent = argumentsList[0]; try { stateNode[InjectEventSign] = originalEvent; } catch (e: any) { console.warn(e.message); } Reflect.apply(target, thisArgument, argumentsList); }, }); props.onClick = new Proxy(props.onClick, { apply: (target, thisArgument, argumentsList) => { try { parseTouchEvent(stateNode[InjectEventSign], (touch) => { try { const node = stateNode._reactInternals; if (touch && node) { trackClick(node, touch); } stateNode[InjectEventSign] = null; } catch (e: any) { console.warn(e.message); } Reflect.apply(target, thisArgument, argumentsList); }); } catch (e: any) { console.warn(e.message); Reflect.apply(target, thisArgument, argumentsList); } }, }); props[InjectSign] = 1; Object.freeze(props); } export function updateProps(stateNode: any) { const props = stateNode.props; if (!props.onClick) { return; } if (props[InjectSign]) { return; } props.onClick = new Proxy(props.onClick, { apply: (target, thisArgument, argumentsList) => { try { parseTouchEvent(stateNode[InjectEventSign], (touch) => { try { const node = stateNode._reactInternals; if (touch && node) { trackClick(node, touch); } stateNode[InjectEventSign] = null; } catch (e: any) { console.warn(e.message); } Reflect.apply(target, thisArgument, argumentsList); }); } catch (e: any) { console.warn(e.message); Reflect.apply(target, thisArgument, argumentsList); } }, }); props[InjectSign] = 1; }