我正在尝试从手势状态中改变状态(React Native Gesture Handler)。
const [localShowRecents, setLocalShowRecents] = useState(false)
const translateY = useSharedValue(0);
const gesture = Gesture.Pan()
.onStart(() => {
context.value = { y: translateY.value }
})
.onUpdate((event) => {
//console.log(event.translationY);
translateY.value = event.translationY + context.value.y;
translateY.value = Math.max(translateY.value, MAX_TRANSLATE_Y)
})
.onEnd(() => {
if (translateY.value > -SCREEN_HEIGHT / 32){
setLocalShowRecents(true); //change state
}
}
当我尝试从“.onEnd()”函数更新状态时,出现错误“尝试从不同的线程同步调用函数”。我该如何正确地从手势处理程序更改状态?