Skip to content

Commit 0d7379b

Browse files
committed
fix: keep drawer anchored to left/right on web
1 parent 86ae0d6 commit 0d7379b

File tree

1 file changed

+27
-39
lines changed
  • packages/react-native-drawer-layout/src/views

1 file changed

+27
-39
lines changed

packages/react-native-drawer-layout/src/views/Drawer.tsx

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export function Drawer({
2626
}: DrawerProps) {
2727
const windowDimensions = useWindowDimensions();
2828

29-
const layout = customLayout ?? windowDimensions;
30-
const drawerWidth = getDrawerWidth({ layout, drawerStyle });
29+
const drawerWidth = getDrawerWidth({
30+
layout: customLayout ?? windowDimensions,
31+
drawerStyle,
32+
});
3133

3234
const progress = useFakeSharedValue(open ? 1 : 0);
3335

@@ -60,22 +62,13 @@ export function Drawer({
6062
const isOpen = drawerType === 'permanent' ? true : open;
6163
const isRight = drawerPosition === 'right';
6264

63-
let translateX = 0;
64-
65-
// The drawer stays in place at open position when `drawerType` is `back`
66-
if (open || drawerType === 'back') {
67-
if (direction === 'rtl') {
68-
translateX = drawerPosition === 'left' ? drawerWidth - layout.width : 0;
69-
} else {
70-
translateX = drawerPosition === 'left' ? 0 : layout.width - drawerWidth;
71-
}
72-
} else {
73-
if (direction === 'rtl') {
74-
translateX = drawerPosition === 'left' ? -layout.width : drawerWidth;
75-
} else {
76-
translateX = drawerPosition === 'left' ? -drawerWidth : layout.width;
77-
}
78-
}
65+
const translateX =
66+
// The drawer stays in place at open position when `drawerType` is `back`
67+
open || drawerType === 'back'
68+
? 0
69+
: drawerPosition === 'left'
70+
? -drawerWidth
71+
: drawerWidth;
7972

8073
const drawerAnimatedStyle =
8174
drawerType !== 'permanent'
@@ -113,6 +106,7 @@ export function Drawer({
113106
position: drawerType === 'permanent' ? 'relative' : 'absolute',
114107
zIndex: drawerType === 'back' ? -1 : 1,
115108
},
109+
drawerPosition === 'right' ? { right: 0 } : { left: 0 },
116110
drawerAnimatedStyle,
117111
drawerStyle,
118112
]}
@@ -122,24 +116,22 @@ export function Drawer({
122116
);
123117

124118
const mainContent = (
125-
<View key="main" style={styles.main}>
126-
<View style={[styles.content, contentAnimatedStyle]}>
127-
<View
128-
aria-hidden={isOpen && drawerType !== 'permanent'}
129-
style={styles.content}
130-
>
131-
{children}
132-
</View>
133-
{drawerType !== 'permanent' ? (
134-
<Overlay
135-
open={open}
136-
progress={progress}
137-
onPress={() => onClose()}
138-
style={overlayStyle}
139-
accessibilityLabel={overlayAccessibilityLabel}
140-
/>
141-
) : null}
119+
<View key="content" style={[styles.content, contentAnimatedStyle]}>
120+
<View
121+
aria-hidden={isOpen && drawerType !== 'permanent'}
122+
style={styles.content}
123+
>
124+
{children}
142125
</View>
126+
{drawerType !== 'permanent' ? (
127+
<Overlay
128+
open={open}
129+
progress={progress}
130+
onPress={() => onClose()}
131+
style={overlayStyle}
132+
accessibilityLabel={overlayAccessibilityLabel}
133+
/>
134+
) : null}
143135
</View>
144136
);
145137

@@ -168,8 +160,4 @@ const styles = StyleSheet.create({
168160
content: {
169161
flex: 1,
170162
},
171-
main: {
172-
flex: 1,
173-
flexDirection: 'row',
174-
},
175163
});

0 commit comments

Comments
 (0)