即使没有卸载,React本机ActivityIndi​​cator也会保持动画

时间:2018-11-14 17:31:10

标签: react-native spinner activity-indicator

我有一些代码可以显示活动指示器一段时间,然后渲染昂贵的组件。

这里是代码

class MyComponent extends React.Component{
  constructor(){
   this.state={isLoading:true,...someOtherStateProps}
  }

  componentDidMount(){
    InteractionManager.runAfterInteractions(()=>{
     /* Expensive Calculations*/
     this.setState(ps=>({isLoading:false}))
    })
  }
  render(){
   if(this.state.isLoading)
     return <ActivityIndicator/>
   return <ComponentThatRendersALongListOfItems/>
  }
}

我的这段代码的问题是,如果存在一个ActivityIndi​​cator,即使将isLoading的状态设置为false,也要花费大量的时间才能真正呈现主视图。如果我将活动指示器替换为返回值null或Loading ...,则我看到的主要组件的延迟很短。我在render方法中放置了2个控制台日志,以确认返回值是来自if部分还是主要部分。我认为,即使在卸载ActivityIndi​​cator之后,它仍会保持动画状态,从而阻止主线程渲染Main组件。有什么帮助或建议吗?

0 个答案:

没有答案
相关问题