2017-12-02 164 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回調中的數據解決了這個問題,並且在對話被解除並且回調發生時,將視圖重新設置爲加載模式。

相關問題