我有一条包含2个场景的路线,第一个场景是装载程序,第二个场景是“主应用程序”。
对于加载程序,我有一个函数可以使用await / async(承诺)更新应用程序中我所有卡的预测,因此,当我第一次启动该应用程序时,它的确非常快,可以通过CALL_API的调度来发出请求,但是当我关闭该应用程序(而不是杀死它)并返回时,我通过操作重定向到加载程序以再次发出调用,但是当我关闭该应用程序时,我需要花费更多的时间,越来越多的时间,我关闭/进入该应用程序,又损失了5秒。
某些代码:
_handleAppStateChange = async (nextAppState) => {
if (this.state.appState.match(/background/) && nextAppState === 'active') {
Actions.loader()
}
this.setState({appState: nextAppState});
}
这部分代码,检查应用程序是否从后台运行到活动状态,并触发这部分代码重定向到路由加载器
// On did mount, I call this function to make the loader
async updateCardsForecast(){
return new Promise(async (res, rej) => {
if(this.props.cards.length > 1){
await this.props.getCoordinates()
const respUpdate = await this.props.updateForecastCurrentCard()
for(let i = 0; i < this.props.otherCards.cards.length; i++) {
let otherCard = this.props.otherCards.cards[i]
const {lat, lng} = otherCard.coordinates
await this.props.updateForecastOtherCards(lat, lng, i)
}
res()
}
else {
await this.props.getCoordinates()
const respUpdate = await this.props.updateForecastCurrentCard()
res()
}
})
}