-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[expo][keep-awake] Fix Unable to deactivate keep awake
warnings
#17319
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.
noticed the ios test suite ci job broken from my accidental copied change. added the last change to fix it 🤞 |
the ios ci jobs failure may come from pod cache with this commit on main branch. i'll merge this pr anyway and open another pr to fix the ios failure. |
…7319) # Why a slightly different proposal of #13432 and to fix #12584 my hypothesis is that in the case, the Activity is dead (`finish()` called) but the process is still alive and the react-native bridge is still alive. before the Activity dead, `deactivateKeepAwake` is called. however, the unhandled promise rejection will be kept in the bridge queue. it will show in the yellow box when next time the new Activity created. sometimes, android will not finish Activity when pressing back button, [especially on android 12](https://developer.android.com/about/versions/12/behavior-changes-all#back-press). to reliably test the issue, i would turn on the `Don't keep activities` flag in android developer menu: <img src="https://user-images.githubusercontent.com/46429/166503633-5d8cfe46-599a-4b35-8f1c-d228a5ab0a40.png" height="500" /> according to the study from #13432, the `FLAG_KEEP_SCREEN_ON` scope is window based. if the Activity is dead, we don't need to remove the flag. # How based on the observations above, my assumption is that it's a common case and we don't need to show the warning. this pr is to remove the warning. - update `activateKeepAwake` and `deactivateKeepAwake` to return `Promise<void>`, so that we can handle to promise rejection. - add `{ suppressDeactivateWarnings: true }` option to suppress the promise rejection. - use the `{ suppressDeactivateWarnings: true }` in `withExpoRoot` # Test Plan #### Integration Test 1. turn on `Don't keep activities` flag in android developer menu. 2. on a sdk45 project 3. launch app -> press back (triangle) button -> press square button to resume the app. see whether the warning is displayed. #### Unit Test ``` useKeepAwake ✓ test default calls without any parameters (6 ms) ✓ test explicit calls with parameters (1 ms) ``` i did try to test the promise rejection. i got no luck to test the promise rejection in hook as well as the `useEffect` cleanup function. (cherry picked from commit 3bbd660)
@siarheipashkevich would be happy to investigate if you could have a minimal reproducible example. |
@Kudo it's very simple we should switch to another tab before the page is loaded. And when I back to tab with my app I saw this error, I think it's because the page is not loaded when the keep awake should be activated.. if you need I can record video |
@siarheipashkevich having these steps and it works for me. so it would be good if you could create a reproducible project for us to investigate. $ yarn create expo-app -t tabs@sdk-48 sdk48
$ cd sdk48
$ npx expo start -w |
Why
a slightly different proposal of #13432 and to fix #12584
my hypothesis is that in the case, the Activity is dead (
finish()
called) but the process is still alive and the react-native bridge is still alive. before the Activity dead,deactivateKeepAwake
is called. however, the unhandled promise rejection will be kept in the bridge queue. it will show in the yellow box when next time the new Activity created.sometimes, android will not finish Activity when pressing back button, especially on android 12. to reliably test the issue, i would turn on the
Don't keep activities
flag in android developer menu:according to the study from #13432, the
FLAG_KEEP_SCREEN_ON
scope is window based. if the Activity is dead, we don't need to remove the flag.How
based on the observations above, my assumption is that it's a common case and we don't need to show the warning. this pr is to remove the warning.
activateKeepAwake
anddeactivateKeepAwake
to returnPromise<void>
, so that we can handle to promise rejection.{ suppressDeactivateWarnings: true }
option to suppress the promise rejection.{ suppressDeactivateWarnings: true }
inwithExpoRoot
Test Plan
Integration Test
Don't keep activities
flag in android developer menu.Unit Test
i did try to test the promise rejection. i got no luck to test the promise rejection in hook as well as the
useEffect
cleanup function.Checklist
expo build
(eg: updated@expo/xdl
).expo prebuild
& EAS Build (eg: updated a module plugin).