[React Native] I'm trying to catch and store the values of a gesture start and end so I can draw bounding boxes on top of a loaded image. So far I can get the starting and ending coordinates and console log them out but when I try to store them in a variable nothing happens and my variable is null when the gesture ends
My code looks a bit like this:
const [startPosition, setStartPosition] = useState<{ x: number; y: number } | null>(null); // Variable to track start position of touch
...
onPanResponderGrant: (evt) => {
const { locationX, locationY } = evt.nativeEvent; // catch the x and y coordinates of the initial gesture
setStartPosition({ x: locationX, y: locationY }); // this should set the start position variable but doesn't for some reason
},
onPanResponderRelease: (evt) => {
const { locationX, locationY } = evt.nativeEvent; // catch the x and y coordinates of the release gesture
if (startPosition) {
console.log('Start position exists:', startPosition); // This should be executing but doesn't because startPosition is null
} else {
console.log('Start position is null'); //
}
},
Any ideas?