Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - sometimes app freezes when opened from background

Recently I noticed some strange bug in my IOS app (on Android I did not see that problem so far).

When the release mode is installed on my real device (the same problem happens even with production app from App Store), and when the app is opened from a background where it was for example 1,2 hours - my app freezes for several seconds (I can scroll my lists but Touchables are not working). Sometimes it freezes 5sec, sometimes 10sec... The freeze time is not constant.

For navigation, I use React Native Navigation. First of all, I thought that it can be a navigation problem - but I can navigate through tabs. So I can navigate through tabs, can scroll FlatLists in the tabs, but the list items are not Touchable - I can click them but onPress is not called. And after several sec when the freeze is over - my app does all pending navigations. Namely it opens all screens which were tapped while the app was frozen...

Who had such kind of problem? And how can I solve this? Please help, I am stuck here a couple of days :(

React-Native: 0.59.10; React: 16.8.3;

Thanks in advance

like image 822
David Avatar asked Dec 11 '19 07:12

David


Video Answer


1 Answers

This exact thing happened to me, but my fix was so dumb, that there is a very high probability your problem might be related to something else. It took me a full day and part of the night to figure out however, so in the off chance it might help, here's what happened to me...

I have a function at the root of my app that initializes some things.

 useEffect(() => {
    dispatch(init())
 }, []);

In some truly bizarre act I had added the following in my init function

setInterval(() => { dispatch(setTabsReady(true)) },0)

What I actually meant was

setTimeout(() => { dispatch(setTabsReady(true)) },0)

Astonishingly, this gem only seemed to affect things when I re-opened the app after switching to another.

It was a truly destructive thing that caused all manner of other strange behavior that I only realized in hindsight was related.

like image 195
Martin Carstens Avatar answered Oct 20 '22 07:10

Martin Carstens