Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawer Navigator Component Overlaps Screen When App Resumes from Background in Modal Presentation Mode #11449

Open
4 of 12 tasks
tom-krusch opened this issue Jul 3, 2023 · 8 comments

Comments

@tom-krusch
Copy link

Current behavior

When using the React Navigation packages with a screen set to the presentation mode "modal" and the app goes into the background and then becomes active again, a Drawer Navigator component unexpectedly overlaps the screen in the background. This issue disrupts the user experience and needs to be addressed.

It doesn't matter if the Drawer Navigator renders a custom drawerContent component or is default.

I have found out that this problem only exists if the drawerPosition: 'right' is set.

Bug.Report.React.Navigation.Modal.Screen.mov

Expected behavior

The Drawer Navigator component remains hidden and does not protrude into the screen.

Reproduction

https://github.com/tom-krusch/SandboxApp

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view

Environment

  • I've removed the packages that I don't use
package version
@react-navigation/native 6.1.7
@react-navigation/bottom-tabs 6.5.8
@react-navigation/drawer 6.6.3
@react-navigation/native-stack 6.9.13
react-native-safe-area-context 4.6.3
react-native-screens 3.22.0
react-native-gesture-handler 2.12.0
react-native-reanimated 3.3.0
react-native-tab-view 3.5.2
react-native-pager-view 6.2.0
react-native 0.72.1
node 18.16.0
npm or yarn yarn
@tom-krusch
Copy link
Author

I have now investigated myself and found out the following.
The problem occurs because in the DrawerView the current width is determined by useSafeAreaFrame.
However, if the screen goes into the background natively, it is scaled and the relative width does not change.
but the useSafeAreaFrame hook returns the actual width, so it is smaller.

to fix this without update i use patch-package
here is my change:

diff --git a/node_modules/@react-navigation/drawer/src/views/DrawerView.tsx b/node_modules/@react-navigation/drawer/src/views/DrawerView.tsx
index 9ec1d45..81908ab 100644
--- a/node_modules/@react-navigation/drawer/src/views/DrawerView.tsx
+++ b/node_modules/@react-navigation/drawer/src/views/DrawerView.tsx
@@ -18,9 +18,9 @@ import {
   Platform,
   StyleSheet,
   View,
+  useWindowDimensions
 } from 'react-native';
 import * as Reanimated from 'react-native-reanimated';
-import { useSafeAreaFrame } from 'react-native-safe-area-context';
 
 import type {
   DrawerContentComponentProps,
@@ -122,7 +122,7 @@ function DrawerViewBase({
     setLoaded([...loaded, focusedRouteKey]);
   }
 
-  const dimensions = useSafeAreaFrame();
+  const dimensions = useWindowDimensions();
 
   const { colors } = useTheme();
 

@JordyYeoman
Copy link

@tom-krusch - We have also been facing similar issues, your solution worked.
It might be worth opening an MR to get this as part of the main package.

Unless there's reason to continue using the useSafeAreaFrame().

@eikhunter
Copy link

Yup, just upgraded and facing this issue, I believe it may be related to the same change useLegacyImplimentation being deprecated. The patch works! Thanks

@royjayperryman
Copy link

Still seeing this issue in the latest version 6.6.6. Is anyone opening a MR for this to be the solution? @tom-krusch @eikhunter

@bhandanyan-nomad
Copy link

bhandanyan-nomad commented Dec 22, 2023

My app is experiencing this issue also caused by a third party package (react-native-auth0) which uses a modal screen to display their authentication window. The patch seems to work for us. Would like to see this incorporated into a future version as well.

EDIT: appears there's a PR for it already but it's been blocked so far
#11632

@bhandanyan-nomad
Copy link

@osdnk how do you propose this issue gets resolved?

@bhandanyan-nomad
Copy link

@satya164 what do you think?

@danielschuetter
Copy link

we have the same issue!
Thanks for the patch @tom-krusch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants