Skip to content

Commit

Permalink
fix: prevent back handler usage on web (#11458)
Browse files Browse the repository at this point in the history
**Motivation**

- fix #11316
  • Loading branch information
EvanBacon authored and kacperkapusciak committed Jul 31, 2023
1 parent c4a6f87 commit e5f753f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/drawer/src/views/DrawerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ function DrawerViewBase({
}
};

if (Platform.OS === 'web') {
document?.body?.addEventListener?.('keyup', handleEscape);
return () => {
document?.body?.removeEventListener?.('keyup', handleEscape);
};
}

// We only add the listeners when drawer opens
// This way we can make sure that the listener is added as late as possible
// This will make sure that our handler will run first when back button is pressed
Expand All @@ -177,16 +184,8 @@ function DrawerViewBase({
handleHardwareBack
);

if (Platform.OS === 'web') {
document?.body?.addEventListener?.('keyup', handleEscape);
}

return () => {
subscription.remove();

if (Platform.OS === 'web') {
document?.body?.removeEventListener?.('keyup', handleEscape);
}
subscription?.remove?.();
};
}, [
defaultStatus,
Expand Down
1 change: 1 addition & 0 deletions packages/native/src/useBackButton.web.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function useBackButton() {}

0 comments on commit e5f753f

Please sign in to comment.