blur text input and hide suggestions when the soft keyboard is closed #143
1 changed files with 23 additions and 1 deletions
|
@ -8,6 +8,20 @@ import uriBarStyle from '../../styles/uriBar';
|
||||||
class UriBar extends React.PureComponent {
|
class UriBar extends React.PureComponent {
|
||||||
static INPUT_TIMEOUT = 500;
|
static INPUT_TIMEOUT = 500;
|
||||||
|
|
||||||
|
textInput = null;
|
||||||
|
|
||||||
|
keyboardDidHideListener = null;
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.keyboardDidHideListener) {
|
||||||
|
this.keyboardDidHideListener.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -42,6 +56,13 @@ class UriBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_keyboardDidHide = () => {
|
||||||
|
if (this.textInput) {
|
||||||
|
this.textInput.blur();
|
||||||
|
}
|
||||||
|
this.setState({ focused: false });
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { navigation, suggestions, updateSearchQuery, value } = this.props;
|
const { navigation, suggestions, updateSearchQuery, value } = this.props;
|
||||||
if (this.state.currentValue === null) {
|
if (this.state.currentValue === null) {
|
||||||
|
@ -66,7 +87,8 @@ class UriBar extends React.PureComponent {
|
||||||
onPress={() => this.handleItemPress(item)} />} />
|
onPress={() => this.handleItemPress(item)} />} />
|
||||||
</View>)}
|
</View>)}
|
||||||
<View style={uriBarStyle.uriContainer}>
|
<View style={uriBarStyle.uriContainer}>
|
||||||
<TextInput style={uriBarStyle.uriText}
|
<TextInput ref={(ref) => { this.textInput = ref }}
|
||||||
|
style={uriBarStyle.uriText}
|
||||||
selectTextOnFocus={true}
|
selectTextOnFocus={true}
|
||||||
placeholder={'Search for videos, music, games and more'}
|
placeholder={'Search for videos, music, games and more'}
|
||||||
underlineColorAndroid={'transparent'}
|
underlineColorAndroid={'transparent'}
|
||||||
|
|
Loading…
Reference in a new issue