I am thinking of having something like this https://android-arsenal.com/details/1/3941 where you have icon that you press to show password as plaintext, not as dots. However, I was unable to find any custom component that would help me.
I don't want to put too much time on such a minor feature, so I'm asking without having attempted anything yet: Is there a custom component I've missed? If not, is there a simple way to add children to TextInput? Or should I just have TextInput and Touchable side by side?
So here is the complete step by step tutorial for Set Image Icon Inside TextInput in React Native Android iOS Example. You can freely download Icons for your apps from Google Material Design Icons. 1. Create a Folder named as Images inside your Project. 2. Download the below ic_person.png icon and Put the icon inside the Images folder.
We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run Run the following commands to create a new React Native project
Use react-native-vector-icons as you can render it inside a text component. But if you want to use it as if it were inside a TextInput you have to wrap Icon and TextInput inside a View: Thanks it worked..not inside of textinput but that's okay...thanku for your time and help..
Basically you can’t put an icon inside of a textInput but you can fake it by wrapping it inside a view and setting up some simple styling rules. set flexDirection of the parent to ‘row’ which will align the children next to each other give TextInput flex 1 so it takes the full width of the parent View
You can use combination of View, Icon and TextInput like so:
<View style={styles.searchSection}> <Icon style={styles.searchIcon} name="ios-search" size={20} color="#000"/> <TextInput style={styles.input} placeholder="User Nickname" onChangeText={(searchString) => {this.setState({searchString})}} underlineColorAndroid="transparent" /> </View>
and use flex-direction for styling
searchSection: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#fff', }, searchIcon: { padding: 10, }, input: { flex: 1, paddingTop: 10, paddingRight: 10, paddingBottom: 10, paddingLeft: 0, backgroundColor: '#fff', color: '#424242', },
Icons were taken from "react-native-vector-icons"
Basically you can’t put an icon inside of a textInput but you can fake it by wrapping it inside a view and setting up some simple styling rules.
Here's how it works:
Code:
<View style={styles.passwordContainer}> <TextInput style={styles.inputStyle} autoCorrect={false} secureTextEntry placeholder="Password" value={this.state.password} onChangeText={this.onPasswordEntry} /> <Icon name='what_ever_icon_you_want' color='#000' size={14} /> </View>
Style:
passwordContainer: { flexDirection: 'row', borderBottomWidth: 1, borderColor: '#000', paddingBottom: 10, }, inputStyle: { flex: 1, },
(Note: the icon is underneath the TextInput so it appears on the far right, if it was above TextInput it would appear on the left.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With