-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathMobileMenuDrawer.tsx
78 lines (70 loc) · 2.24 KB
/
MobileMenuDrawer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {
BottomSheetBackdrop,
BottomSheetBackdropProps,
BottomSheetModal,
BottomSheetView,
} from '@gorhom/bottom-sheet';
import { ReactNode, forwardRef, useImperativeHandle, useRef } from 'react';
import { Keyboard } from 'react-native';
import { useReducedMotion } from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useTheme } from '@storybook/react-native-theming';
interface MobileMenuDrawerProps {
children: ReactNode | ReactNode[];
}
export interface MobileMenuDrawerRef {
setMobileMenuOpen: (isOpen: boolean) => void;
}
export const BottomSheetBackdropComponent = (backdropComponentProps: BottomSheetBackdropProps) => (
<BottomSheetBackdrop
{...backdropComponentProps}
appearsOnIndex={0}
disappearsOnIndex={-1}
pressBehavior={'close'}
style={[backdropComponentProps.style, { backgroundColor: 'rgba(0,0,0,0.5)' }]}
/>
);
export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawerProps>(
({ children }, ref) => {
const reducedMotion = useReducedMotion();
const insets = useSafeAreaInsets();
const theme = useTheme();
const menuBottomSheetRef = useRef<BottomSheetModal>(null);
useImperativeHandle(ref, () => ({
setMobileMenuOpen: (open: boolean) => {
if (open) {
menuBottomSheetRef.current?.present();
} else {
Keyboard.dismiss();
menuBottomSheetRef.current?.dismiss();
}
},
}));
return (
<BottomSheetModal
ref={menuBottomSheetRef}
index={1}
animateOnMount={!reducedMotion}
snapPoints={['50%', '75%']}
enableDismissOnClose
enableHandlePanningGesture
enableContentPanningGesture
enableDynamicSizing={false}
keyboardBehavior="extend"
keyboardBlurBehavior="restore"
stackBehavior="replace"
backdropComponent={BottomSheetBackdropComponent}
backgroundStyle={{ backgroundColor: theme.background.content }}
handleIndicatorStyle={{ backgroundColor: theme.textMutedColor }}
>
<BottomSheetView
style={{
flex: 1,
}}
>
{children}
</BottomSheetView>
</BottomSheetModal>
);
}
);