react-native - 世博会图像很慢而且性能不好但是为什么
问题描述
我有很多故事,大概20-30个。每个故事都有一个图像。如果我滚动图像非常慢并且它的滞后(挂出)。我用这个:https ://dev.to/dmitryame/implementing-fast-image-for-react-native-expo-apps-1dn3
但是如果我在 state 中添加一个新的 Story (Image) ,那么新的 Image 就不会显示。
你用什么来快速读取图像性能好?
小片段:
...
const [storys, setStorys] = useState(route.params.storys || []);
...
<ScrollView>
<ScrollView
horizontal={true}
contentContainerStyle={{height: 100, marginLeft: 12}}
scrollEventThrottle={50}
showsHorizontalScrollIndicator={false}
decelerationRate="normal"
>
{
storys.length > 0
?
storys.map((el, i) => {
return (
<TouchableOpacity key={`index-${i}`} style={{padding: 0, marginRight: 12, borderWidth: 2, justifyContent: 'center', alignItems: 'center', borderRadius: 100, borderColor: 'red', height: 88, width: 88}}>
<Image source={{uri: `http://xx.xxxx.xx:3000/uploads/${el.source}`}} style={{height: 55, width: 55, borderRadius: 500}} />
</TouchableOpacity>
)
})
:
<Text>Es sind zurzeit keine Storys vorhanden.</Text>
}
</ScrollView>
</ScrollView>
解决方案
先安装这些,
npm i react-native-expo-image-cache
然后
npm i expo-blur
然后像这样导入..
import { Image } from "react-native-expo-image-cache";
像这样使用它..
<Image
style={{height: 55, width: 55, borderRadius: 500}}
uri={`http://xx.xxxx.xx:3000/uploads/${el.source}`}
preview={{ uri: `http://xx.xxxx.xx:3000/uploads/${el.source}` }} // Here if you have a preview of the image then place it here...
/>
推荐阅读
- vue.js - 如何在 Vue Vuetify 中使用单个添加节点按钮添加树视图节点?
- rabbitmq - 如何使用 QPid 生成 basic.return
- python - PyCUDA 中的内存分配顺序是否重要?
- javascript - 数字显示为 NaN
- tensorflow - tf.keras.layers.Conv2D 获取内核值
- .net - 将字符串拆分为行并使用.net检查当前行和下一行
- laravel - 更新当前布尔值的相反值
- php - Javascript 时间戳在 Laravel 中被 Carbon 解析为错误日期
- php - 附加到 XML 的末尾时,formatOutput 不起作用,但在第一次创建文件时,formatOutput 工作正常
- css - 将反应门户居中在父元素的顶部