Skip to content

Commit 7c99b9d

Browse files
committed
fix: don't make the overlay touchable if drawer isn't open
1 parent 0a08688 commit 7c99b9d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/drawer/src/views/legacy/Drawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ export default class DrawerView extends React.Component<DrawerProps> {
575575
// Disable overlay if sidebar is permanent
576576
drawerType === 'permanent' ? null : (
577577
<Overlay
578+
pointerEvents={isOpen ? 'auto' : 'none'}
578579
progress={progress}
579580
onPress={() => this.toggleDrawer(false)}
580581
style={overlayStyle as any}

packages/drawer/src/views/modern/Overlay.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as React from 'react';
22
import { Platform, Pressable, StyleSheet } from 'react-native';
3-
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
3+
import Animated, {
4+
useAnimatedProps,
5+
useAnimatedStyle,
6+
} from 'react-native-reanimated';
47

58
const PROGRESS_EPSILON = 0.05;
69

@@ -17,17 +20,23 @@ const Overlay = React.forwardRef(function Overlay(
1720
return {
1821
opacity: progress.value,
1922
// We don't want the user to be able to press through the overlay when drawer is open
20-
// One approach is to adjust the pointerEvents based on the progress
21-
// But we can also send the overlay behind the screen
23+
// We can send the overlay behind the screen to avoid it
2224
zIndex: progress.value > PROGRESS_EPSILON ? 0 : -1,
2325
};
2426
});
2527

28+
const animatedProps = useAnimatedProps(() => {
29+
return {
30+
pointerEvents: progress.value > PROGRESS_EPSILON ? 'auto' : 'none',
31+
} as const;
32+
});
33+
2634
return (
2735
<Animated.View
2836
{...props}
2937
ref={ref}
3038
style={[styles.overlay, overlayStyle, animatedStyle, style]}
39+
animatedProps={animatedProps}
3140
>
3241
<Pressable onPress={onPress} style={styles.pressable} />
3342
</Animated.View>

0 commit comments

Comments
 (0)