fix: fix drawer overlay on web

This commit is contained in:
Satyajit Sahoo
2021-04-08 05:46:18 +02:00
parent ef7370b215
commit 3241190b19
2 changed files with 16 additions and 33 deletions

View File

@@ -8,14 +8,9 @@ import {
StatusBar,
View,
InteractionManager,
Pressable,
} from 'react-native';
import Animated from 'react-native-reanimated';
import {
PanGestureHandler,
TapGestureHandler,
GestureState,
} from '../GestureHandler';
import { PanGestureHandler, GestureState } from '../GestureHandler';
import Overlay from './Overlay';
import DrawerProgressContext from '../../utils/DrawerProgressContext';
import type { DrawerProps } from '../../types';
@@ -449,18 +444,6 @@ export default class DrawerView extends React.Component<DrawerProps> {
},
]);
private handleTapStateChange = event([
{
nativeEvent: {
oldState: (s: Animated.Value<number>) =>
cond(
eq(s, GestureState.ACTIVE),
set(this.manuallyTriggerSpring, TRUE)
),
},
},
]);
private handleContainerLayout = (e: LayoutChangeEvent) =>
this.containerWidth.setValue(e.nativeEvent.layout.width);
@@ -593,18 +576,12 @@ export default class DrawerView extends React.Component<DrawerProps> {
</View>
{
// Disable overlay if sidebar is permanent
drawerType === 'permanent' ? null : Platform.OS === 'web' ||
Platform.OS === 'windows' ||
Platform.OS === 'macos' ? (
<Pressable onPress={() => this.toggleDrawer(false)}>
<Overlay progress={progress} style={overlayStyle as any} />
</Pressable>
) : (
<TapGestureHandler
onHandlerStateChange={this.handleTapStateChange}
>
<Overlay progress={progress} style={overlayStyle as any} />
</TapGestureHandler>
drawerType === 'permanent' ? null : (
<Overlay
progress={progress}
onPress={() => this.toggleDrawer(false)}
style={overlayStyle as any}
/>
)
}
</Animated.View>

View File

@@ -1,5 +1,5 @@
import * as React from 'react';
import { Platform, StyleSheet } from 'react-native';
import { Pressable, Platform, StyleSheet } from 'react-native';
import Animated from 'react-native-reanimated';
const {
@@ -16,10 +16,11 @@ const PROGRESS_EPSILON = 0.05;
type Props = React.ComponentProps<typeof Animated.View> & {
progress: Animated.Node<number>;
onPress: () => void;
};
const Overlay = React.forwardRef(function Overlay(
{ progress, style, ...props }: Props,
{ progress, onPress, style, ...props }: Props,
ref: React.Ref<Animated.View>
) {
const animatedStyle = {
@@ -45,7 +46,9 @@ const Overlay = React.forwardRef(function Overlay(
{...props}
ref={ref}
style={[styles.overlay, overlayStyle, animatedStyle, style]}
/>
>
<Pressable onPress={onPress} style={styles.pressable} />
</Animated.View>
);
});
@@ -63,6 +66,9 @@ const styles = StyleSheet.create({
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
pressable: {
flex: 1,
},
});
export default Overlay;