我正在从react-native-reanimateduseAnimatedScrollHandler
调用钩子来处理我在. 这个钩子按预期工作,但我现在想禁用基于which is a的自定义按钮(My FlatButton) 。但是当 sharedValue 改变时,屏幕不会重新渲染,因为状态没有改变,所以我的按钮的外观保持不变。
有没有办法强制在工作集内重新渲染,或者是否可以使用强制从工作集内重新渲染?onScroll
Animated.ScrollView
currentIndex
sharedValue
useState
const scrollHandler = useAnimatedScrollHandler((event) => {
translationX.value = event.contentOffset.x
if (event.contentOffset.x < width * 0.5 && currentIndex.value != 0) {
currentIndex.value = 0
} else if (
event.contentOffset.x > width * 0.5 &&
event.contentOffset.x < width * 1.5 &&
currentIndex.value != 1
) {
currentIndex.value = 1
} else if (event.contentOffset.x > width * 1.5 && currentIndex.value != 2) {
currentIndex.value = 2
}
})
<FlatButton
label="Next"
disabled={
(currentIndex.value == 0 && (!firstName || !lastName)) ||
(currentIndex.value == 1 && (!dateOfBirth || !sex)) ||
(currentIndex.value == 2 &&
(!streetNumber || !postalCode || !city || !state || !country))
}
onPress={() => {
if (currentIndex.value == 0) {
scrollRef.current
?.getNode()
.scrollTo({ x: width, animated: true })
} else if (currentIndex.value == 1) {
scrollRef.current?.getNode().scrollToEnd({ animated: true })
}
}}
/>