onfocus react native code example
Example 1: react native elements input highlight onfous
You can achieve this by passing in the onFocus and onBlur events to set and unset styles when focused and blurred:
onFocus() {
this.setState({
backgroundColor: 'green'
})
},
onBlur() {
this.setState({
backgroundColor: '#ededed'
})
},
And then, in the TextInput do this:
<TextInput
onBlur={ () => this.onBlur() }
onFocus={ () => this.onFocus() }
style={{ height:60, backgroundColor: this.state.backgroundColor, color: this.state.color }} />
Example 2: react native textinput
import React, { Component } from 'react';
import { TextInput } from 'react-native';
export default function UselessTextInput() {
const [textInputValue, setTextInputValue] = React.useState('');
return (
<TextInput
style={{
height: 40,
borderColor: 'gray',
borderWidth: 1,
placeholderTextColor: 'gray',
}}
onChangeText={text => setTextInputValue(text)}
value={textInputValue}
placeholder="Insert your text!"
/>
);
}
Example 3: text input phone number react native
npm i react-native-phone-input --save