-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent sleep timer from running on native platforms #1786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good and it works, just had some questions about some of the code
shouldReportActivity | ||
&& (appState === CONST.APP_STATE.INACTIVE || appState === CONST.APP_STATE.BACKGROUND) | ||
&& state === CONST.APP_STATE.ACTIVE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand this but basically this is only change the app state if the user has become active and the stored state is not active right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. We set up the state (assume to be active when the app inits) then listen for changes and save it locally each time so we can detect a change from one state to another.
AppState.addEventListener('change', appStateChangeCallback); | ||
return () => { | ||
AppState.removeEventListener('change', appStateChangeCallback); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what is happening here? I'm not totally sure what this is doing, is it initializing with an event listener and then whenever it is returned it gets removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! So, addBecameActiveListener
is both setting up an event listener and then returning a function that we can call later to remove the listener. The appStateChangeCallback
exists in the closure created by calling the outermost function. It's just sort of a convenient pattern for cleaning up the listener we created and I borrowed it from how NetInfo
works.
Sweet, thanks for the explanations, makes sense! |
@marcaaron Any way we could test the callbacks on our side? Or should we just test that the app is updated after reopening it from background? |
That should work! It's the only way to test this without having to look at the logs to verify that they are running correctly. |
Details
This sleep timer thing is wreaking certain havoc on native iOS and Android. Not sure why, but probably it should be disabled for now to restore performance on native apps. My current theory is that other work on the JS thread can cause the timer to get out of whack and cause reconnection callbacks to fire.
Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/157445
Tests
iOS/Android
Web/Desktop
Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android