【发布时间】:2020-01-07 21:13:01
【问题描述】:
我想在 react-native 标题中添加按钮,该按钮是在页面中 mas 和 unmask 密码,当我更改状态以更改 secureTextEntry 值时单击的问题,图标不会更改将保持初始值; 功能正常,但图标无法更改
this.state.secureTextEntry ? "eye" : "eye-slash"
这是主要代码
class ChangePasswordScreen extends Component {
constructor(props) {
super(props);
this.state = {
newPassword: null,
currentPassword: null,
confirmPassword: null,
errors: [],
secureTextEntry: true
};
this.maskPassword = this.maskPassword.bind(this)
}
componentDidMount() {
this.props.navigation.setParams({
headerRight: ( < TouchableOpacity onPress = {
() => {
this.maskPassword();
}
} > < Icon style = {
styles.eyeIcon
}
name = {
this.state.secureTextEntry ? "eye" : "eye-slash"
}
size = {
20
}
color = {
Colors.WHITE
}
/></TouchableOpacity > )
})
}
static navigationOptions = ({
navigation
}) => {
return {
// headerTitle: <LogoTitle />,
headerRight: navigation.state.params && navigation.state.params.headerRight,
};
};
maskPassword = () => {
this.setState({
secureTextEntry: !this.state.secureTextEntry
})
}
}
【问题讨论】:
标签: reactjs react-native react-navigation