Skip to content

Commit e3d5ae5

Browse files
authored
Chispinput backspase on Android fix (#1151)
1 parent ecb8264 commit e3d5ae5

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/components/chipsInput/__tests__/index.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ describe('ChipsInput', () => {
6161
expect(removeTagSpy).not.toHaveBeenCalled();
6262
});
6363

64-
it('should ignore key event if platform is Android', () => {
65-
Constants.isAndroid = true;
66-
const pressEvent = {};
67-
_.set(uut.state, 'tags', [{}, {}, {}]);
68-
uut.onKeyPress(pressEvent);
69-
expect(uut.state.tagIndexToRemove).toBe(2);
70-
Constants.isAndroid = false;
71-
});
72-
7364
it('should not update state if input value is not empty', () => {
7465
const pressEvent = {nativeEvent: {key: Constants.backspaceKey}};
7566
_.set(uut.state, 'tags', [{}, {}, {}]);

src/components/chipsInput/index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
4-
import ReactNative, {NativeModules, StyleSheet, ViewPropTypes, Image, DeviceEventEmitter} from 'react-native';
4+
import ReactNative, {NativeModules, StyleSheet, ViewPropTypes, Image} from 'react-native';
55
import {Constants} from '../../helpers';
66
import {Colors, BorderRadiuses, ThemeManager, Typography} from '../../style';
77
import Assets from '../../assets';
@@ -105,17 +105,10 @@ class ChipsInput extends Component {
105105
const textInputHandle = ReactNative.findNodeHandle(this.input);
106106
if (textInputHandle && NativeModules.TextInputDelKeyHandler) {
107107
NativeModules.TextInputDelKeyHandler.register(textInputHandle);
108-
DeviceEventEmitter.addListener('onBackspacePress', this.onKeyPress);
109108
}
110109
}
111110
}
112111

113-
componentWillUnmount() {
114-
if (Constants.isAndroid) {
115-
DeviceEventEmitter.removeListener('onBackspacePress', this.onKeyPress);
116-
}
117-
}
118-
119112
static getDerivedStateFromProps(nextProps, prevState) {
120113
if (nextProps.tags !== prevState.initialTags) {
121114
return {
@@ -169,10 +162,10 @@ class ChipsInput extends Component {
169162
this.setState({tagIndexToRemove: tagIndex});
170163
}
171164

172-
onChangeText = (value) => {
165+
onChangeText = _.debounce((value) => {
173166
this.setState({value, tagIndexToRemove: undefined});
174167
_.invoke(this.props, 'onChangeText', value);
175-
}
168+
}, 0);
176169

177170
onTagPress(index) {
178171
const {onTagPress} = this.props;
@@ -212,7 +205,7 @@ class ChipsInput extends Component {
212205
const tagsCount = _.size(tags);
213206
const keyCode = _.get(event, 'nativeEvent.key');
214207
const hasNoValue = _.isEmpty(value);
215-
const pressedBackspace = Constants.isAndroid || keyCode === Constants.backspaceKey;
208+
const pressedBackspace = keyCode === Constants.backspaceKey;
216209
const hasTags = tagsCount > 0;
217210

218211
if (pressedBackspace) {

0 commit comments

Comments
 (0)