Repository navigation
migrate deprecated onBackPressed() - #51096
Closed
alanleedev wants to merge 1 commit into
Closed
alanleedev wants to merge 1 commit into
alanleedev wants to merge 1 commit into
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D74161428 |
Summary: **Problem:** `Activity.onBackPressed()` has been deprecated and with targetSdk 36, predictive back will be enforced and the API no longer called. We need to migrate to backward compatible AndroidX `OnBackPressedCallback`. - https://developer.android.com/about/versions/16/behavior-changes-16#predictive-back. **Solution:** `OnBackPressedCallback` is registered conditionally only if it is `targetSdk` 36 or greater. If the callback in enabled, `onBackPressed()` is not called and callback is used regardless of `android:enableOnBackInvokedCallback` property in <application> or <activity> set in AndroidManifest.xml. As a workaround callback is manually calling existing `onBackPressed()`. This is done rather than removing onBackPressed() completely and using only `OnBackPressedCallback` as we are not sure of the impact of removing the implementation entirely. Once we determine it is safe to do so then, we should remove the workaround and fully transition to `OnBackPressedCallback` * I also surveyed child classes extending ReactActivity for overridden `onPressedBack()` usage and found only one usage which will be handled later. NOTE: `ReactDelegate.onHostResume()` sets up the `DefaultHardwareBackBtnHandler` using `ReactActivity` (https://fburl.com/ul47tbeo) and will be called from JS `BackHanderl.exitApp` (https://fburl.com/code/a4l2pjsw). Calling `BackHanderl.exitApp` enables predictive back to work. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D74161428
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D74161428 |
Contributor
|
This pull request has been merged in bc876fb. |
Collaborator
|
This pull request was successfully merged by @alanleedev in bc876fb When will my fix make it into a release? | How to file a pick request? |
react-native-bot
pushed a commit
that referenced
this pull request
May 19, 2025
Summary: Pull Request resolved: #51096 **Problem:** `Activity.onBackPressed()` has been deprecated and with targetSdk 36, predictive back will be enforced and the API no longer called. We need to migrate to backward compatible AndroidX `OnBackPressedCallback`. - https://developer.android.com/about/versions/16/behavior-changes-16#predictive-back. **Solution:** `OnBackPressedCallback` is registered conditionally only if it is `targetSdk` 36 or greater. If the callback in enabled, `onBackPressed()` is not called and callback is used regardless of `android:enableOnBackInvokedCallback` property in <application> or <activity> set in AndroidManifest.xml. As a workaround callback is manually calling existing `onBackPressed()`. This is done rather than removing onBackPressed() completely and using only `OnBackPressedCallback` as we are not sure of the impact of removing the implementation entirely. Once we determine it is safe to do so then, we should remove the workaround and fully transition to `OnBackPressedCallback` * I also surveyed child classes extending ReactActivity for overridden `onPressedBack()` usage and found only one usage which will be handled later. NOTE: `ReactDelegate.onHostResume()` sets up the `DefaultHardwareBackBtnHandler` using `ReactActivity` (https://fburl.com/ul47tbeo) and will be called from JS `BackHanderl.exitApp` (https://fburl.com/code/a4l2pjsw). Calling `BackHanderl.exitApp` enables predictive back to work. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D74161428 fbshipit-source-id: 2e081ba6922b315e9d1746e83a41bab5277fa62e
Collaborator
|
This pull request was successfully merged by @alanleedev in 0e3764c When will my fix make it into a release? | How to file a pick request? |
26 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Problem:
Activity.onBackPressed()has been deprecated and with targetSdk 36, predictive back will be enforced and the API no longer called. We need to migrate to backward compatibleOnBackPressedCallback.Solution:
OnBackPressedCallbackis registered conditionally only if it istargetSdk36 or greater.If the callback in enabled,
onBackPressed()is not called and callback is used regardless ofandroid:enableOnBackInvokedCallbackproperty in or set in AndroidManifest.xml.As a workaround callback is manually calling existing
onBackPressed().This is done rather than removing onBackPressed() completely and using only
OnBackPressedCallbackas we are not sure of the impact of removing the implementation entirely. Once we determine it is safe to do so then, we should remove the workaround and fully transition toOnBackPressedCallbackNOTE:
ReactDelegate.onHostResume()sets up theDefaultHardwareBackBtnHandlerusingReactActivity(https://fburl.com/ul47tbeo) and will be called from JSBackHanderl.exitApp(https://fburl.com/code/a4l2pjsw).Changelog:
[Internal]
Differential Revision: D74161428