android - React-Native 自定义标记减慢应用程序
问题描述
当我使用自定义标记时,经过几个进程后系统开始变得沉重。但是如果我没有定制就使用它,是没有问题的。我分享了我的 Marker 代码的截图,为什么我可能会遇到这样的问题。
所以如果我使用默认标记也没关系。但如果我自己设计它,它的工作速度会非常慢。
标记数量:50
库:react-native-maps、react-native-vector-icons/FontAwesome5
关:
tracksViewChanges={false}
我通过向标记添加道具解决了这个问题
trackViewChanges:设置此标记是否应跟踪视图更改。建议在可能提高自定义标记性能时将其关闭。
renderListMarker = () => {
let { markerList } = this.props;
return (
markerList.map((item, index) => {
return (
<Marker
onPress={() => { this.selectMarker(index) }}
key={item._id}
coordinate={{
latitude: item.location.coordinates[0],
longitude: item.location.coordinates[1],
}}
>
<View style={{ flexDirection: 'column', justifyContent: 'center', alignItems: 'center' }}>
<View style={{ marginBottom: -18, flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
<View style={{ marginEnd: 2 }}>
<FontAwesome5 name="parking" size={24} color={this.state.marker === index ? "#3879f0" : "#000000"} />
</View>
{
item.empty !== false ? <View style={{ padding: 2, borderRadius: 2, backgroundColor: item.empty > 0 ? '#00cc96' : '#e63946', }}>
<Text style={{ color: '#ffffff', fontWeight: 'bold', fontSize: 12 }}>{item.empty}</Text>
</View> : null
}
</View>
<View style={{ justifyContent: 'center' }}>
<FontAwesome5 name="sort-down" size={30} color={this.state.marker === index ? "#3879f0" : "#000000"} />
</View>
</View>
</Marker>
)
}
)
)
}
解决方案
推荐阅读
- math - 如何实现自适应步长 Runge-Kutta Cash-Karp?
- makefile - 如何使用 cmake 增量生成 makefile
- ssh - 通过 SSH 隧道进行远程调试:接收“在套接字 y 上发送 x 字节时出现问题:管道损坏”
- php - 带有值会话的 JSON 文件?
- javascript - 在不使用 async/await 的情况下按顺序执行一组 Promise
- c# - Datagridview - 将选定的单元格复制到新的 DataTable
- http - 除了在流式传输 HTTP 数据时出现错误关闭客户端连接之外,服务器还能做任何事情吗?
- tkinter - 插入带有标签的行时出现 Tkinter Treeview 问题
- reactjs - 重新渲染具有更新值的组件后,如何更新输入和下拉列表中的值?
- typescript - Typescript - 具有任意数量键值的对象