fix uri bar text input handling
This commit is contained in:
parent
5ae5144eda
commit
13136e606d
1 changed files with 16 additions and 10 deletions
|
@ -46,10 +46,16 @@ class UriBar extends React.PureComponent {
|
||||||
const { currentRoute: prevRoute } = this.props;
|
const { currentRoute: prevRoute } = this.props;
|
||||||
|
|
||||||
if (Constants.DRAWER_ROUTE_SEARCH === currentRoute && currentRoute !== prevRoute) {
|
if (Constants.DRAWER_ROUTE_SEARCH === currentRoute && currentRoute !== prevRoute) {
|
||||||
this.setState({ currentValue: query, inputText: query }, () => this.setCaretPosition(query));
|
this.setState({ currentValue: query, inputText: query }, () => this.setCaretPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChange = evt => {
|
||||||
|
if (evt.nativeEvent && evt.nativeEvent.text) {
|
||||||
|
this.setCaretPosition();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
handleChangeText = text => {
|
handleChangeText = text => {
|
||||||
const newValue = text || '';
|
const newValue = text || '';
|
||||||
clearTimeout(this.state.changeTextTimeout);
|
clearTimeout(this.state.changeTextTimeout);
|
||||||
|
@ -75,11 +81,7 @@ class UriBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}, UriBar.INPUT_TIMEOUT);
|
}, UriBar.INPUT_TIMEOUT);
|
||||||
}
|
}
|
||||||
this.setState({ inputText: newValue, currentValue: newValue, changeTextTimeout: timeout }, () => {
|
this.setState({ inputText: newValue, currentValue: newValue, changeTextTimeout: timeout });
|
||||||
if (newValue || newValue.length > 0) {
|
|
||||||
this.setCaretPosition(newValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleItemPress = item => {
|
handleItemPress = item => {
|
||||||
|
@ -133,9 +135,12 @@ class UriBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCaretPosition(text) {
|
setCaretPosition() {
|
||||||
if (this.textInput && text && text.length >= 0) {
|
if (this.textInput) {
|
||||||
this.textInput.setNativeProps({ selection: { start: text.length, end: text.length } });
|
const text = this.textInput.props.value;
|
||||||
|
if (text && text.length > 0) {
|
||||||
|
this.textInput.setNativeProps({ selection: { start: text.length, end: text.length } });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +194,7 @@ class UriBar extends React.PureComponent {
|
||||||
value,
|
value,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
if (this.state.currentValue === null) {
|
if (this.state.currentValue === null) {
|
||||||
this.setState({ currentValue: value }, () => this.setCaretPosition(value));
|
this.setState({ currentValue: value }, () => this.setCaretPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = [
|
let style = [
|
||||||
|
@ -282,6 +287,7 @@ class UriBar extends React.PureComponent {
|
||||||
this.setSelection();
|
this.setSelection();
|
||||||
}}
|
}}
|
||||||
onChangeText={this.handleChangeText}
|
onChangeText={this.handleChangeText}
|
||||||
|
onChange={this.handleChange}
|
||||||
onSubmitEditing={this.handleSubmitEditing}
|
onSubmitEditing={this.handleSubmitEditing}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue