在文件 popUpDialog.Js
export default class DialogTester extends Component {
constructor(props) {
super(props)
this.state = {
dialogVisible: false
};
}
showDialog = () => {
this.setState({ dialogVisible: true });
};
handleCancel = () => {
this.setState({ dialogVisible: false });
};
handleRedefinir = () => {
this.setState({ dialogVisible: false });
};
handleEmail = (email) => {
console.log(email);
}
render() {
const {dialogVisible} = this.state;
return (
<View>
<Dialog.Container visible={this.state.dialogVisible}>
<Dialog.Title>Redefinir Senha</Dialog.Title>
<Dialog.Description>
Digite seu e-mail cadastrado
</Dialog.Description>
<Dialog.Input placeholder="E-mail" onChangeText={(email) => this.handleEmail(email)}
></Dialog.Input>
<Dialog.Button label="Cancelar" onPress={this.handleCancel} />
<Dialog.Button label="Redefinir" onPress={this.handleRedefinir} />
</Dialog.Container>
</View>
);
}
}
到目前为止还好
在文件 Index.js
import React, { Component } from "react";
import {
View,
TextInput,
Text,
TouchableOpacity,
SafeAreaView,
StatusBar,
} from "react-native";
import styles from "./styles";
import PopUp from "../Login/popUpDialog";
export default class Login extends Component {
render() {
return (
<SafeAreaView>
<TouchableOpacity
onPress={() => <PopUp dialogVisible = true /> } //It does not work
style={styles.redefinirButton}
>
<Text style={styles.textRedefinirButton}>Redefinir Senha</Text>
</TouchableOpacity>
</SafeAreaView>
);
}
}
当我按下它时如何使 dialogVisible = true ?我尝试道具和 setState 不起作用
其他一切正常,如果我尝试退出 onPress 并将变量保留为默认值,但当我将其保留为 false 并尝试在按下按钮时传递 true 时,我无法以任何方式执行此操作。