2017-08-08 47 views
0

我在我的原生應用程序中使用此庫(https://github.com/jacklam718/react-native-popup-dialog/blob/master/README.md)打開對話框。到目前爲止,我跟着示例代碼,他們已經和它很適合我:React Native調用一個函數在渲染中打開一個對話框

import PopupDialog from 'react-native-popup-dialog'; 

<View style={styles.container}> 
    <Button 
    text="Show Dialog" 
    onPress={() => { 
     this.popupDialog.show(); 
    }} 
    /> 
    <PopupDialog 
    ref={(popupDialog) => { this.popupDialog = popupDialog; }} 
    > 
    <View> 
     <Text>Hello</Text> 
    </View> 
    </PopupDialog> 
</View> 

我的問題是打開的對話框時,我的屏幕首次加載。我試着做類似: {this.popupDialog.show()}和{()=> this.popupDialog.show()}和其他不起作用的變體。我希望能夠打開對話框,不必點擊按鈕來獲取onPress()函數來調用。任何人都可以在正確的地方引導我。

回答

0

您可以使用組件生命週期來調用popupDialog.show()函數。

嘗試添加這對你的看法腳本:

var self = this; 
componentDidMount() { 
    self.popupDialog.show(); 
} 

瞭解更多關於狀態和生命週期在https://facebook.github.io/react/docs/state-and-lifecycle.html

希望這有助於反應。

+0

這工作謝謝! – ghost

相關問題