react-native - 在 React Native 中设置大数组状态时如何消除 UI 的延迟?
问题描述
我React Native
用来渲染一个Chart
.
我的应用程序中有 3 个自定义tabs
项,当在它们之间滑动时,我会获取新数据并应用翻译动画来突出显示选定的选项卡。
滚动时我面临 1 秒的延迟。我调查了延迟,其中有一个参数setState()
导致它,这是一大组数据。
我已经在使用async / await
.
我试图放入setState()
asetTimeout
但最终结果并不顺利。
有没有办法优化在状态中设置大数组?或者从setState()
?
更新
await Animated.spring(translateBottomX, {
toValue: type,
duration: 100,
}).start();
if (segment === 1) {
await Animated.parallel([
Animated.spring(translateXBottomTabOne, {
toValue: 0,
duration: 100,
}).start(),
Animated.spring(translateXBottomTabTwo, {
toValue: width,
duration: 100,
}).start(),
]);
} else if (segment === 2) {
await Animated.parallel([
Animated.spring(translateXBottomTabOne, {
toValue: width,
duration: 100,
}).start(),
Animated.spring(translateXBottomTabTwo, {
toValue: 0,
duration: 100,
}).start(),
]);
} else if (segment === 3) {
await Animated.parallel([
Animated.spring(translateXBottomTabOne, {
toValue: width,
duration: 0,
}).start(),
Animated.spring(translateXBottomTabTwo, {
toValue: width,
duration: 100,
}).start(),
]);
}
setTimeout(() => {
this.setState({
dataAxeX
});
}, 500);
// 在这里使用
<XAxis
data={dataAxeX}
formatLabel={(_, index) => dataAxeX[index].Datetime}
contentInset={styles.xAxisContentInset}
svg={{
fill: "#B6C1DF",
...styles.xAxisStyle,
}}
/>
解决方案
推荐阅读
- javascript - 我正在尝试使用模式视图在 html 中显示两个不同的文本,但是 javascript 重叠并且无法正常工作
- deep-learning - 为什么需要目标网络?
- lotus-notes - 如何使用 IBM Notes 在本地 Web 浏览器中打开数据库
- c++ - 如何确定 std::ofstream 打开的文件的当前大小?
- c# - 测试动作结果
当 BadRequest() 返回时 - groovy - 在 SoapUI 中使用 Groovy 脚本从 xlsx 文件中读取值
- python - 将字节列表写入文件,但有些记录丢失了
- grails - 如何在 grails 3.3.8 中使用导航 API
- javascript - Javascript:如果对象未传递给函数,则忽略解构对象参数
- visual-studio-code - VS Code:按 Crtl - D 后区分大小写替换