问题描述
我在使用 react-native-reanimated 2.1.0
实现的 React Native 0.64 应用程序中有一个简单的 Accordion 组件。动画变量定义为 animatedVar
。相关代码如下:
const aref = useAnimatedRef();
const open = useSharedValue(false);
const animatedVar = useDerivedValue(() => {open.value ? withTiming(1) : withTiming(0)});
const height = useSharedValue(0);
const accordStyle = useAnimatedStyle(() => { //<<== accordStyle causes app stopping working
return {
height: height.value * animatedVar.value + 1,opacity: animatedVar.value === 0 ? 0 : 1,};
});
const pressAccord = async () => {
if (height.value === 0) {
runOnUI(() => {
"worklet";
height.value = measure(aref).height;
})();
}
open.value = !open.value;
};
return (
<>
<TouchableOpacity onPress={() => pressAccord()}>
<View style={styles.titleContainer}>
<Text>{title}</Text>
<Animated.View style={iconStyle}>
<Icon name="chevron-down-outline" size={20} />
</Animated.View>
</View>
</TouchableOpacity>
<Animated.View style={[accordStyle]} > //<<==accordStyle causes app stop working
<View ref={aref} >
{children}
</View>
</Animated.View>
</>
);
如果 accordStyle
从上面的代码中删除,那么手风琴工作正常(我的意思是没有错误)。但如果 app stopped working
包含在 accordStyle
中,应用程序会抛出错误 style
。但我不知道 accordStyle
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)