Commit 8629a34
Allow LogBox and RedBox overlay dismissal via Android back button (#56405)
Summary:
Pull Request resolved: #56405
On Android, pressing the hardware back button while the LogBox inspector is open does nothing. `LogBoxDialog` is explicitly set to `setCancelable(false)` and there's no `onBackPressed()` override, so the back button is completely swallowed. The only way to close the inspector is the on-screen Minimize/Dismiss buttons.
For RedBox, the dialog is cancelable by default so back press does dismiss it visually, but it bypasses `hideRedboxDialog()`. The dialog reference and content view don't get cleaned up, leaving stale state.
This adds proper back button handling for both:
**LogBox**: `LogBoxDialog` now takes an `onRequestClose` callback and overrides `onBackPressed()` to invoke it. The surface delegate passes a callback that emits `hardwareBackPress` to the JS runtime, where a new `BackHandler` listener in `LogBoxInspector` calls `onMinimize()`. This keeps `setCancelable(false)` in place (so tapping outside the dialog doesn't dismiss it) while still running the full dismiss flow through JS: state reset, `NativeLogBox.hide()`, dialog cleanup.
**RedBox**: The anonymous `Dialog` subclass now overrides `onBackPressed()` to call `hideRedboxDialog()` directly, which dismisses the dialog, destroys the content view, and nulls the reference.
Changelog: [Internal] - Allow LogBox and RedBox overlays to respond to Android back button press
Reviewed By: alanleedev
Differential Revision: D100081099
fbshipit-source-id: cabec9b75fb3e733662457bc34de006a45a114941 parent 0d1b70e commit 8629a34
3 files changed
Lines changed: 19 additions & 2 deletions
File tree
- packages/react-native
- Libraries/LogBox/UI
- ReactAndroid/src/main/java/com/facebook/react/devsupport
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
0 commit comments