[Android] Add onUserLeaveHint support to ReactActivityDelegate#43488
[Android] Add onUserLeaveHint support to ReactActivityDelegate#43488behenate wants to merge 4 commits into
Conversation
# Conflicts: # packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java
… assert it, fix explicit API issues
Base commit: 6c50418 |
|
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@cortinico merged this pull request in 3cf6c64. |
|
This pull request has been reverted by f2f62cd. |
|
@behenate sadly this had to be reverted once more due to a crash on one of our internal products. I'll get back to you on Monday with more details and we'll see what are the next steps |
|
@cortinico Interesting, I'm not sure what could be causing a crash in this code as it's pretty straightforward. Waiting for more info! |
|
@behenate so the app gets stuck on the loading screen with this stacktrace: |
|
I'm unsure why |
|
@cortinico I'm also not sure why onUserLeaveHint is called this early in the app, but it should be safe to ignore it. I will make another PR tomorrow. Hopefully third time's the charm 🙃 |
Yup I also have repros instruction to verify if the app still crashes so we can see if all is green |
Summary: This PR adds `onUserLeaveHint` support into the `ReactActivityDelegate`. It allows modules to receive an event every time user moves the app into the background. This is slightly different than `onPause` - it's called only when the user intentionally moves the app into the background, e.g. when receiving a call `onPause` should be called but `onUserLeaveHint` shouldn't. This feature is especially useful for libraries implementing features like Picture in Picture (PiP), where using `onUserLeaveHint` is the [recommended way of auto-entering PiP](https://developer.android.com/develop/ui/views/picture-in-picture#:~:text=You%20might%20want%20to%20include%20logic%20that%20switches%20an%20activity%20into%20PiP%20mode%20instead%20of%20going%20into%20the%20background.%20For%20example%2C%20Google%20Maps%20switches%20to%20PiP%20mode%20if%20the%20user%20presses%20the%20home%20or%20recents%20button%20while%20the%20app%20is%20navigating.%20You%20can%20catch%20this%20case%20by%20overriding%20onUserLeaveHint()%3A) for android < 12. This is a re-submission of #42741 and #43488 without problematic asserts, which were unnecessary (`onUserLeaveHint` is not critical to the lifecycle of the app), but were causing problems in some apps. ## Changelog: [ANDROID] [ADDED] - Added `onUserLeaveHint` support into `ReactActivityDelegate` Pull Request resolved: #43567 Test Plan: Tested in the `rn-tester` app - callbacks are correctly called on both old and new architecture. Reviewed By: javache Differential Revision: D55123632 Pulled By: cortinico fbshipit-source-id: 144a1d84b691af9cf3c0cffad446e674b4b68927
…ok#43488" (facebook#43623) Summary: Pull Request resolved: facebook#43623 Original commit changeset: 144a1d84b691 Original Phabricator Diff: D55123632 Differential Revision: D55218594
…ok#43488" Summary: Original commit changeset: 144a1d84b691 Original Phabricator Diff: D55123632 Differential Revision: D55218594
…ok#43488" Summary: Changelog: [internal] This change broke some apps at Meta. Reverting until we figure out a safe way to land this. Differential Revision: D55324557
|
Sadly we have to revert this once more as it's causing a couple of internal apps to fail. Here the stacktrace: |
Summary:
This PR adds
onUserLeaveHintsupport into theReactActivityDelegate. It allows modules to receive an event every time user moves the app into the background. This is slightly different thanonPause- it's called only when the user intentionally moves the app into the background, e.g. when receiving a callonPauseshould be called butonUserLeaveHintshouldn't.This feature is especially useful for libraries implementing features like Picture in Picture (PiP), where using
onUserLeaveHintis the recommended way of auto-entering PiP for android < 12.This is a re-submission of #42741. The problematic
asserthas been changed to anif- it's not a problem if onUserLeaveHint is received from an activity different to the current one, but in that case we shouldn't emit the event.Changelog:
[ANDROID] [ADDED] - Added
onUserLeaveHintsupport intoReactActivityDelegateTest Plan:
Tested in the
rn-testerapp - callbacks are correctly called on both old and new architecture.