mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
30 lines
978 B
TypeScript
30 lines
978 B
TypeScript
import { getCurrentRoute } from "navigation/navigationUtils";
|
|
import React from "react";
|
|
import type { GestureResponderEvent, PressableProps } from "react-native";
|
|
import { Pressable } from "react-native";
|
|
import { log } from "sharedHelpers/logger";
|
|
|
|
const logger = log.extend( "PressableWithTracking" );
|
|
|
|
const PressableWithTracking = React.forwardRef<typeof Pressable, PressableProps>(
|
|
( props, ref ) => {
|
|
const { onPress, ...otherProps } = props;
|
|
|
|
const handlePressWithTracking = ( event: GestureResponderEvent ) => {
|
|
if ( otherProps?.testID ) {
|
|
const currentRoute = getCurrentRoute( );
|
|
logger.info( `Button tap: ${otherProps?.testID}-${currentRoute?.name || "undefined"}` );
|
|
}
|
|
|
|
if ( onPress ) {
|
|
onPress( event );
|
|
}
|
|
};
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
return <Pressable {...otherProps} onPress={handlePressWithTracking} ref={ref} />;
|
|
}
|
|
);
|
|
|
|
export default PressableWithTracking;
|