remove state.value and rely only on props.value (#2635)

This commit is contained in:
Saturnino Abril 2019-03-20 22:15:01 +08:00 committed by GitHub
parent 676babf313
commit e744083833
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,22 +68,11 @@ export default class SearchBarAndroid extends PureComponent {
constructor(props) {
super(props);
this.state = {
value: props.value,
isFocused: false,
refocusInput: true,
};
}
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.value !== prevState.value) {
return {
value: nextProps.value,
};
}
return null;
}
cancel = () => {
this.onCancelButtonPress();
};
@ -107,7 +96,6 @@ export default class SearchBarAndroid extends PureComponent {
InteractionManager.runAfterInteractions(() => {
this.setState({
isFocused: false,
value: '',
}, () => {
this.props.onCancelButtonPress();
});
@ -119,9 +107,7 @@ export default class SearchBarAndroid extends PureComponent {
};
onChangeText = (value) => {
this.setState({value}, () => {
this.props.onChangeText(value);
});
this.props.onChangeText(value);
};
onSelectionChange = (event) => {
@ -219,7 +205,7 @@ export default class SearchBarAndroid extends PureComponent {
ref='input'
blurOnSubmit={blurOnSubmit}
refocusInput={this.state.refocusInput}
value={this.state.value}
value={this.props.value}
autoCapitalize={autoCapitalize}
autoCorrect={false}
returnKeyType={returnKeyType || 'search'}