Константа стиля, возвращаемая useAnimatedStyle, приводит к прекращению работы приложения
У меня есть простой компонент Accordion в приложении React Native 0.64, реализованный с помощью
react-native-reanimated 2.1.0
. Анимированная переменная определяется как
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>
</>
);
Если удалить из кода выше, то аккордеон работает нормально (я имел в виду без ошибок). Но приложение выдает ошибку
app stopped working
если входит в
style
. Но я не мог понять, что не так
accordStyle