Skip to content

Commit

Permalink
fix: fix right drawer layouts display over content (#11651)
Browse files Browse the repository at this point in the history
**Motivation**

Using the example project if you set the `drawerPosition="right"` and
`drawerType="front"` (the default for the example) the drawer is
positioned in the middle of the screen. Other combinations of these
settings are also affected including at least `drawerType="slide"` with
`drawerPosition="right"`.

It seems to be platform independent. I'm able to reproduce on web, iOS,
and Android. Below is a screenshot from web on mobile in landscape.

Image of the issue: 

![image](https://github.com/react-navigation/react-navigation/assets/40714964/c33e3747-5e09-4f9e-9052-4f14c0bbb3ac)

When using the RTL setting in the example app it became clear that It
needs the same logic for `isRTL` that the Drawer Navigator has.

I took the logic from the Drawer Navigator related to `I18nManager` from
`react-native` and leveraged it in the react-native-drawer-layout. It
appears these two extremely similar. Perhaps it's worth leveraging the
react-native-drawer-layout package for drawer navigation and maintaining
it in one place but that's beyond the scope of this pr/issue.

**Test plan**

To test using the example, set `drawerPosition="right"` and
`drawerType="front"` (example currently had front already set) for a
Drawer from react-native-drawer-layout. The layout will should be off
screen on the right. Not in the middle hovering above the content.

Image of resolved issue (with drawer open).

![image](https://github.com/react-navigation/react-navigation/assets/40714964/bb1f0996-8f7d-4796-9350-2917c6a01e8d)

---------

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
  • Loading branch information
brannonvann and satya164 committed Mar 8, 2024
1 parent f6e9836 commit f6772c6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/react-native-drawer-layout/src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ export function Drawer({
});

const drawerAnimatedStyle = useAnimatedStyle(() => {
const distanceFromEdge = layout.width - drawerWidth;

return {
transform:
drawerType === 'permanent'
Expand All @@ -365,7 +367,8 @@ export function Drawer({
{
translateX:
// The drawer stays in place when `drawerType` is `back`
drawerType === 'back' ? 0 : translateX.value,
(drawerType === 'back' ? 0 : translateX.value) +
(drawerPosition === 'left' ? 0 : distanceFromEdge),
},
],
};
Expand Down

0 comments on commit f6772c6

Please sign in to comment.