我有一个在点击时切换的组件,它在expo go中工作正常,但在运行Android应用程序构建后,它给出了以下错误:
java.lang.NullPointerException:尝试对空对象引用调用接口方法“intcom.facebook.react.bridge.ReadableArray.size()”
enter image description here
const [open, setOpen] = useState(false);
const navigation = useNavigation();
return (
<>
<Pressable
onPress={() => {
if (!!props.category?.children) setOpen((prevState) => !prevState);
else {
// @ts-ignore
navigation.navigate({
name: "Category",
params: { category: props.category },
key: "Category-" + props.category.id,
});
}
}}
>
<View style={styles.categoryItem}>
<View style={styles.rightView}>
<View style={styles.imageBox}>
<Image
style={styles.image}
source={{ uri: props.category.image }}
/>
</View>
<Text style={styles.title}>{props.category.name}</Text>
</View>
{!!props.category.children && (
<Svg
style={[
styles.arrow,
open && { transform: [{ rotate: "90deg" }] },
]}
width="20"
height="20"
viewBox="0 0 28 28"
fill="none"
>
<Path
d="M20.1523 14.1445C20.1523 14.4521 20.0381 14.7158 19.792 14.9443L12.9541 21.6416C12.7607 21.835 12.5146 21.9404 12.2246 21.9404C11.6445 21.9404 11.1787 21.4834 11.1787 20.8945C11.1787 20.6045 11.3018 20.3496 11.4951 20.1475L17.6562 14.1445L11.4951 8.1416C11.3018 7.93945 11.1787 7.67578 11.1787 7.39453C11.1787 6.80566 11.6445 6.34863 12.2246 6.34863C12.5146 6.34863 12.7607 6.4541 12.9541 6.64746L19.792 13.3359C20.0381 13.5732 20.1523 13.8369 20.1523 14.1445Z"
fill="rgba(117, 117, 117, 0.5)"
/>
</Svg>
)}
</View>
</Pressable>
<View style={[styles.children, !open && { display: "none" }]}>
{props.category.children?.map((child) => (
<TouchableOpacity
onPress={() => {
// @ts-ignore
navigation.navigate({
name: "Category",
params: { category: child },
key: "Category-" + child.id,
});
}}
key={child.id}
style={styles.child}
>
<Text style={styles.childTitle}>{child.name}</Text>
<View style={styles.underLine}></View>
</TouchableOpacity>
))}
</View>
</>
);
1条答案
按热度按时间6ioyuze21#
我发现了错误所在。问题是这个元素不能正确地与transform一起工作。所以我这样修改了代码: