I want to unfocus all of my TextInput`s when I click on TouhableOpacity.
I have learned that I can use refs for achieve that. But when I use single ref with several TextInputs I got that behaviour with only last TextInput
class UserRegister extends React.Component<any, State> {
private inputRef: React.RefObject<TextInput>;
constructor(props:any) {
super(props);
//some code
this.inputRef = React.createRef();
}
onSwitchPicker = () => {
if (this.inputRef.current) {
this.inputRef.current.blur();
}
//some code
}
render() {
return (
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<TextInput
ref={this.inputRef}
//other params
/>
<TextInput
ref={this.inputRef}
//other params
/>
<TouchableOpacity
onPress={this.onSwitchPicker}
//other params
>
//some code
</TouchableOpacity>
// some code
</KeyboardAvoidingView>
);
}
}