fix crash on search (#1594)

This commit is contained in:
Saturnino Abril 2018-04-17 21:23:28 +08:00 committed by Harrison Healey
parent a5662cc747
commit effc99462b
2 changed files with 11 additions and 9 deletions

View file

@ -30,6 +30,7 @@ export default class Autocomplete extends PureComponent {
static defaultProps = {
isSearch: false,
cursorPosition: 0,
};
state = {

View file

@ -81,6 +81,7 @@ export default class Search extends PureComponent {
this.isX = DeviceInfo.getModel() === 'iPhone X';
this.state = {
channelName: '',
cursorPosition: 0,
value: '',
managedConfig: {},
};
@ -123,10 +124,6 @@ export default class Search extends PureComponent {
mattermostManaged.removeEventListener(this.listenerId);
}
attachAutocomplete = (c) => {
this.autocomplete = c;
};
cancelSearch = preventDoubleTap(() => {
const {navigator} = this.props;
this.handleTextChanged('', true);
@ -173,9 +170,10 @@ export default class Search extends PureComponent {
};
handleSelectionChange = (event) => {
if (this.autocomplete) {
this.autocomplete.getWrappedInstance().handleSelectionChange(event);
}
const cursorPosition = event.nativeEvent.selection.end;
this.setState({
cursorPosition,
});
};
handleTextChanged = (value, selectionChanged) => {
@ -490,7 +488,10 @@ export default class Search extends PureComponent {
} = this.props;
const {intl} = this.context;
const {value} = this.state;
const {
cursorPosition,
value,
} = this.state;
const style = getStyleFromTheme(theme);
const sections = [{
data: [{
@ -625,7 +626,7 @@ export default class Search extends PureComponent {
stickySectionHeadersEnabled={Platform.OS === 'ios'}
/>
<Autocomplete
ref={this.attachAutocomplete}
cursorPosition={cursorPosition}
onChangeText={this.handleTextChanged}
isSearch={true}
value={value}