jwohlfert23 / react-native-tag-input

A simple React Native component that creates an input for tags, emails, etc.
MIT License
231 stars 104 forks source link

onChange gets called with an empty array #64

Closed thatjuan closed 4 years ago

thatjuan commented 6 years ago

I've set up a TagInput pretty similar to the way it's set up in the example. When I type a new tag, the previous tag gets removed.

I suspect it's because of this line: https://github.com/jwohlfert23/react-native-tag-input/blob/90e8a50d187a807b58ff3454eb25ce31c478b78f/index.js#L219

What's the purpose of this line?

pruthvirajkarur commented 6 years ago

Even i am facing the same issue and its only for IOS.

nol13 commented 6 years ago

Which version of RN? >= 0.54?

Dupe of this? https://github.com/jwohlfert23/react-native-tag-input/issues/55

thatjuan commented 6 years ago

0.55 on iOS.

nol13 commented 6 years ago

There is a bug in recent versions of RN where Backspace gets called incorrectly when the TextInput is cleared, so it doesn't return in the 'if' check below and then gets pop'd. And I think another bug where the value wasn't getting set right.

if (this.props.text !== '' || event.nativeEvent.key !== 'Backspace') {
      return;
}
const tags = [...this.props.value];
tags.pop();

There are PR's up that fix it, but who knows when it'll make it out to release. Have a branch off of 0.55.4 with the 2 patches applied that fixed the issues for me, if useful to anyone.

https://github.com/nol13/react-native/tree/TextInput-Patch-0.55.4

Ashoat commented 6 years ago

Thanks for researching this bug @nol13! It looks like there are two issues, yeah?

nol13 commented 6 years ago

Ya two issues, need both patches to get normal behavior. Not really sure of/qualified to speak about the relative merit of 19087 vs. 18456, as far as I can tell both work, just need one or the other.

The backspace patch is needed to fix the issue where you can only add one tag. The other fixes a bunch of weird behavior where the js and native values can get out of sync or something after adding a few tags, and events stop firing, backspace will delete tags even if there is still text, etc.

maharjanaman commented 6 years ago

@nol13 any workaround for expo users?

nol13 commented 6 years ago

i think downgrading to expo 25 would do it, if that's a possibility.

(and saw backspace fix merged, thanks for moving that along!)

Edit: is fixed in 0.57 in case anyone comes across this still

LaurieWilliamsNZ commented 5 years ago

Expo 25 is deprecated. Still getting this issue in the latest version of expo.