react-native - 无法在 StackNavigator 中显示对话框 - React Native
问题描述
嗨,我在按下headerRight
StackNavigator 中的按钮时显示对话框时遇到问题。我收到一条错误消息:_this.setState 不是函数。(在 _this.setState({visible:true})) _this.setState 是 undefined。这是我的代码:
state = {
visible: false,
};
_showDialog = () => this.setState({ visible: true });
_hideDialog = () => this.setState({ visible: false });
const AppStackNavigator = createStackNavigator({
DrawerNavigator:{
screen: DrawerNavigator,
navigationOptions: ({navigation}) => ({
title: 'Fabiola Voyance',
headerTintColor: 'white',
headerStyle: {
backgroundColor: '#8cc866',
},
headerMode: 'none',
headerLeft: (
<TouchableOpacity style={{marginLeft: 10 }} onPress={ () =>{ navigation.openDrawer()}}>
<Icon color="white" name="menu" size={30} />
</TouchableOpacity>
),
}),
},
Accueil: {
screen: Accueil,
navigationOptions: {
title: 'Horoscope',
headerTintColor: 'white',
headerStyle: {
backgroundColor: '#8cc866',
},
},
},
VoyanteProfil: {
screen: VoyanteProfil,
navigationOptions: (navigation) => ({
headerTintColor: 'white',
headerStyle: {
backgroundColor: '#8cc866'
},
headerMode: 'none',
headerRight: (
<TouchableOpacity onPress = {() => {this._showDialog()} }>
<View style={{borderRadius: 30, overflow: 'hidden', alignItems: 'center',backgroundColor:'white', justifyContent: 'center', marginRight:20 }}>
<Image style={{ width:35, height: 35 }} source={require("../Images/icone-sonnerie.png")}/>
<Dialog
animationType = "fade"
contentStyle= {
{
alignItems:"center",
justifyContent:"center",
}
}
visible={this.state.visible}
onDismiss={this._hideDialog}>
<View>
<Text style = {{textAlign: 'center', fontSize:18}}>La Voyance Privée offre une consultation sans attentes, sans limite de temps et sans interruption</Text>
</View>
<View style = {{marginTop:15,marginBottom:15}}>
<MyButton style={{}} text={"Voyance privée\nouvert 24h/24\n"} icone='icone-transfert'/>
</View>
<View>
<Text style = {{textAlign:'center', fontSize:18}}>La Voyance Directe sans CB permet de choisir un des Médiums présents sur le moment</Text>
</View>
<View style = {{marginTop:15,marginBottom:15}}>
<MyButton text={"Voyance sans CB\nouvert 24h/24\n"} icone='icone-sonnerie'/>
</View>
</Dialog>
</View>
</TouchableOpacity>
)
}),
},
解决方案
推荐阅读
- sql-server - SQL Server 2019 在提供程序列表中看不到 Oracle 12.2.0 OraOLEDB12.dll
- python - val_accuracy 不增加
- azure-devops - 变量的 Azure DevOps 条件初始化不起作用
- python - 多线程,我的代码有什么问题
- python - 是否可以为“f”字符串全局设置精度?
- python - 使用 matplotlib 和 pandas 在给定的 (y) 截止值以下注释最小值
- docker - 在 Ubuntu 18.04 VM (VirtualBox) 上安装 Docker 时出现哈希和不匹配错误等
- bash - 是否可以将 linux 管道中的值放入 curl 查询字符串参数中?
- android - 如何使 ViewPager 适合标签页?
- amazon-web-services - EC2用户数据脚本不重定向`user-data.log`输出到控制台