因此,在创建文本输入组件时遇到问题,就像IGNITE CLI创建名为RoundedButton的组件时一样(如下所示)。我想创建一个类似的组件,但是要创建一个TextInput,它可以输出正常的输出,并在需要时通过简单的调整即可输出一个****字符。我怎样才能做到这一点?
这是RoundedButton的代码:
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { TouchableOpacity, Text } from 'react-native'
import styles from './Styles/RoundedButtonStyles'
import ExamplesRegistry from '../Services/ExamplesRegistry'
// Note that this file (App/Components/RoundedButton) needs to be
// imported in your app somewhere, otherwise your component won't be
// compiled and added to the examples dev screen.
// Ignore in coverage report
/* istanbul ignore next */
ExamplesRegistry.addComponentExample('Rounded Button', () =>
<RoundedButton
text='real buttons have curves'
onPress={() => window.alert('Rounded Button Pressed!')}
/>
)
export default class RoundedButton extends Component {
static propTypes = {
onPress: PropTypes.func,
text: PropTypes.string,
children: PropTypes.string,
navigator: PropTypes.object
}
getText () {
const buttonText = this.props.text || this.props.children || ''
return buttonText.toUpperCase()
}
render () {
return (
<TouchableOpacity style={styles.button} onPress={this.props.onPress}>
<Text style={styles.buttonText}>{this.getText()}</Text>
</TouchableOpacity>
)
}
}
答案 0 :(得分:1)
将secureTextEntry链接到组件状态/属性,并在按下按钮时对其进行更改。
像这样:
secureTextEntry={this.state.showDots}
然后按下按钮
onPress = () => {
this.setState({ showDots: true/false})
}