I'm trying to return the values of .measure
but it seems the code inside can't interact without using a state, and so it keeps returning false. I'm trying to avoid using a state because I need the value inside my PanResponder
Measure function returns false
const showRefPosition = assignedRef => {
let maxHeight = false;
assignedRef.measure((x, y, width, height, pageX, pageY) => {
const maxY = SCREEN_HEIGHT - height;
maxHeight = pageY - maxY < 40;
});
console.log("new maxHeight", maxHeight);
return maxHeight;
};
What I'm trying to do: is to get the elements position inside the PanResponder
My problem
I'm trying to get the elements position inside the PanResponder
, but keep getting the wrong value (default value). Or the state inside the PanResponder
doesn't update.
PanResponder
const panResponder = useRef(
PanResponder.create({
onMoveShouldSetPanResponder: (event, gestureState) => {
console.log("showRefPosition", showRefPosition(this.AnimatedRef));
if (event.nativeEvent.pageY < 100) {
pan.flattenOffset();
Animated.spring(pan, {
toValue: { x: 0, y: -600 },
}).start();
return false;
}
return Math.abs(gestureState.dy) > Math.abs(gestureState.dx * 3);
},