2017-08-08 43 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

相关问题