Skip to content

Add BackHandler to dismiss LogBox toasts on back press (#56474)#56474

Open
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Abbondanzo:export-D101178179
Open

Add BackHandler to dismiss LogBox toasts on back press (#56474)#56474
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Abbondanzo:export-D101178179

Conversation

@Abbondanzo
Copy link
Copy Markdown
Contributor

@Abbondanzo Abbondanzo commented Apr 16, 2026

Summary:

On Android, pressing the hardware back button while LogBox notification toasts or the full inspector overlay are visible has no effect on the JS side. The only way to dismiss notifications is the on-screen X button, and the only way to close the inspector is via Minimize/Dismiss.

This adds BackHandler listeners to both JS containers:

Notification toasts: A new LogBoxNotificationBackHandler component mounts alongside the toasts and registers a hardwareBackPress listener that calls clearWarnings() + clearErrors(), equivalent to pressing X on every visible toast. The component returns null and auto-cleans the listener on unmount.

Inspector overlay: LogBoxInspectorContainer registers a hardwareBackPress listener in componentDidMount that calls _handleMinimize() (setSelectedLog(-1)), closing the overlay non-destructively — same as pressing the Minimize button.

Changelog: [Android][Added] - Allow LogBox notification toasts and inspector overlay to be dismissed via Android back button

Differential Revision: D101178179

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 16, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 16, 2026

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D101178179.

@meta-codesync meta-codesync bot changed the title Add BackHandler to dismiss LogBox toasts on back press Add BackHandler to dismiss LogBox toasts on back press (#56474) Apr 16, 2026
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Apr 16, 2026
Summary:

On Android, pressing the hardware back button while LogBox notification toasts or the full inspector overlay are visible has no effect on the JS side. The only way to dismiss notifications is the on-screen X button, and the only way to close the inspector is via Minimize/Dismiss.

This adds `BackHandler` listeners to both JS containers:

**Notification toasts**: A new `LogBoxNotificationBackHandler` component mounts alongside the toasts and registers a `hardwareBackPress` listener that calls `clearWarnings()` + `clearErrors()`, equivalent to pressing X on every visible toast. The component returns null and auto-cleans the listener on unmount.

**Inspector overlay**: `LogBoxInspectorContainer` registers a `hardwareBackPress` listener in `componentDidMount` that calls `_handleMinimize()` (`setSelectedLog(-1)`), closing the overlay non-destructively — same as pressing the Minimize button.

Changelog: [Android][Added] - Allow LogBox notification toasts and inspector overlay to be dismissed via Android back button

Differential Revision: D101178179
Summary:

On Android, pressing the hardware back button while LogBox notification toasts or the full inspector overlay are visible has no effect on the JS side. The only way to dismiss notifications is the on-screen X button, and the only way to close the inspector is via Minimize/Dismiss.

This adds `BackHandler` listeners to both JS containers:

**Notification toasts**: A new `LogBoxNotificationBackHandler` component mounts alongside the toasts and registers a `hardwareBackPress` listener that calls `clearWarnings()` + `clearErrors()`, equivalent to pressing X on every visible toast. The component returns null and auto-cleans the listener on unmount.

**Inspector overlay**: `LogBoxInspectorContainer` registers a `hardwareBackPress` listener in `componentDidMount` that calls `_handleMinimize()` (`setSelectedLog(-1)`), closing the overlay non-destructively — same as pressing the Minimize button.

Changelog: [Android][Added] - Allow LogBox notification toasts and inspector overlay to be dismissed via Android back button

Differential Revision: D101178179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant