sskhandek / react-native-emoji-input

A fully-featured emoji keyboard ⌨️ for React Native ⚛️
MIT License
71 stars 38 forks source link

Don't call RecyclerView methods in setTimeout call when component is already unmounted #32

Closed darekg11 closed 5 years ago

darekg11 commented 5 years ago

Relate to any issue?

Nope

Breaking change?

Nope

What this PR does?

Because the following code is happening in setTimeout call:

this._recyclerListView._pendingScrollToOffset = null;
this._recyclerListView.scrollToTop(false);

what can happen and actually happen to us is that the component itself might be already unmounted but the setTimeout callout will still happen trying to access those fields and crash. This was happening in following situation:

  1. React-Native-Emoji-Picker is opened in Modal Window.
  2. User starts typing in search input.
  3. User immediately hits back button on Android to close the modal.
  4. Component gets unmounted but setTimeout call is already queued so it will happen anyway.

That if just guards access to those fields only if component is still mounted.

rijn commented 5 years ago

I would suggest renaming the value to _isMounted which is given by the react tutorial.

darekg11 commented 5 years ago

Will push change today / tomorrow.

darekg11 commented 5 years ago

Have to close this one in favor of:
https://github.com/sskhandek/react-native-emoji-input/pull/33 Since I don't have access anymore to organization account from which I have created original PR and I can't push there.