2017-12-02 163 views
0

我使用https://github.com/jacklam718/react-native-dialog-component作为我的对话框,而且我在使用异步函数时没有刷新对话框。我在例如使用它像使用react-native-dialog-component显示它之前在对话框中强制刷新

render() { 
    return (
     ... 
     <Button onItemPressed={(item) => { 
        this.completeMovementDialog.show() 
       }}/>} 
     ... 
     <CompleteMovementDialog onRefresh={() => this.getStationsNearToPlayer()} 
         ref={(completeMovementDialog) => { 
           this.completeMovementDialog = completeMovementDialog; 
          }}/> 

的CompleteMovementDialog使用在componentDidMount()的onRefresh方法,是一个DialogComponent的包装。当我刷新列表时,它工作正常,从后端检索this.getStationsNearToPlayer()。问题在于,CompleteMovementDialog组件一旦被加载,组件就会被加载。所以当我打电话给this.startMovementDialog.show()时,它不会再进入componentDidMount,并且除非手动刷新,否则不会刷新列表。有没有人有提示,我可以如何在show()之前提前刷新清单?还是有更好的库来显示对话框?听说ref是不是一个好的做法...

回答

0

穿过这有人绊脚石:

DialogComponent提供onShownonDismissed财产,在那里你可以通过一个功能,即可以是一个API调用。我通过加载onShown回调中的数据解决了这个问题,并且在对话被解除并且回调发生时,将视图重新设置为加载模式。

相关问题