react-native-drawer-layout 2.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +235 -35
- package/lib/commonjs/constants.js +15 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/DrawerGestureContext.js +12 -0
- package/lib/commonjs/utils/DrawerGestureContext.js.map +1 -0
- package/lib/commonjs/utils/DrawerProgressContext.js +12 -0
- package/lib/commonjs/utils/DrawerProgressContext.js.map +1 -0
- package/lib/commonjs/utils/useDrawerProgress.js +19 -0
- package/lib/commonjs/utils/useDrawerProgress.js.map +1 -0
- package/lib/commonjs/views/Drawer.js +89 -0
- package/lib/commonjs/views/Drawer.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.android.js +17 -0
- package/lib/commonjs/views/GestureHandler.android.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.ios.js +17 -0
- package/lib/commonjs/views/GestureHandler.ios.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.js +33 -0
- package/lib/commonjs/views/GestureHandler.js.map +1 -0
- package/lib/commonjs/views/GestureHandlerNative.js +37 -0
- package/lib/commonjs/views/GestureHandlerNative.js.map +1 -0
- package/lib/commonjs/views/legacy/Drawer.js +419 -0
- package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
- package/lib/commonjs/views/legacy/Overlay.js +74 -0
- package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
- package/lib/commonjs/views/modern/Drawer.js +285 -0
- package/lib/commonjs/views/modern/Drawer.js.map +1 -0
- package/lib/commonjs/views/modern/Overlay.js +69 -0
- package/lib/commonjs/views/modern/Overlay.js.map +1 -0
- package/lib/module/constants.js +5 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/DrawerGestureContext.js +3 -0
- package/lib/module/utils/DrawerGestureContext.js.map +1 -0
- package/lib/module/utils/DrawerProgressContext.js +3 -0
- package/lib/module/utils/DrawerProgressContext.js.map +1 -0
- package/lib/module/utils/useDrawerProgress.js +10 -0
- package/lib/module/utils/useDrawerProgress.js.map +1 -0
- package/lib/module/views/Drawer.js +81 -0
- package/lib/module/views/Drawer.js.map +1 -0
- package/lib/module/views/GestureHandler.android.js +2 -0
- package/lib/module/views/GestureHandler.android.js.map +1 -0
- package/lib/module/views/GestureHandler.ios.js +2 -0
- package/lib/module/views/GestureHandler.ios.js.map +1 -0
- package/lib/module/views/GestureHandler.js +21 -0
- package/lib/module/views/GestureHandler.js.map +1 -0
- package/lib/module/views/GestureHandlerNative.js +11 -0
- package/lib/module/views/GestureHandlerNative.js.map +1 -0
- package/lib/module/views/legacy/Drawer.js +409 -0
- package/lib/module/views/legacy/Drawer.js.map +1 -0
- package/lib/module/views/legacy/Overlay.js +64 -0
- package/lib/module/views/legacy/Overlay.js.map +1 -0
- package/lib/module/views/modern/Drawer.js +276 -0
- package/lib/module/views/modern/Drawer.js.map +1 -0
- package/lib/module/views/modern/Overlay.js +60 -0
- package/lib/module/views/modern/Overlay.js.map +1 -0
- package/lib/typescript/src/constants.d.ts +5 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +110 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/DrawerGestureContext.d.ts +4 -0
- package/lib/typescript/src/utils/DrawerGestureContext.d.ts.map +1 -0
- package/lib/typescript/src/utils/DrawerProgressContext.d.ts +5 -0
- package/lib/typescript/src/utils/DrawerProgressContext.d.ts.map +1 -0
- package/lib/typescript/src/utils/useDrawerProgress.d.ts +3 -0
- package/lib/typescript/src/utils/useDrawerProgress.d.ts.map +1 -0
- package/lib/typescript/src/views/Drawer.d.ts +20 -0
- package/lib/typescript/src/views/Drawer.d.ts.map +1 -0
- package/lib/typescript/src/views/GestureHandler.android.d.ts +2 -0
- package/lib/typescript/src/views/GestureHandler.android.d.ts.map +1 -0
- package/lib/typescript/src/views/GestureHandler.d.ts +15 -0
- package/lib/typescript/src/views/GestureHandler.d.ts.map +1 -0
- package/lib/typescript/src/views/GestureHandler.ios.d.ts +2 -0
- package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +1 -0
- package/lib/typescript/src/views/GestureHandlerNative.d.ts +6 -0
- package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -0
- package/lib/typescript/src/views/legacy/Drawer.d.ts +51 -0
- package/lib/typescript/src/views/legacy/Drawer.d.ts.map +1 -0
- package/lib/typescript/src/views/legacy/Overlay.d.ts +89 -0
- package/lib/typescript/src/views/legacy/Overlay.d.ts.map +1 -0
- package/lib/typescript/src/views/modern/Drawer.d.ts +10 -0
- package/lib/typescript/src/views/modern/Drawer.d.ts.map +1 -0
- package/lib/typescript/src/views/modern/Overlay.d.ts +89 -0
- package/lib/typescript/src/views/modern/Overlay.d.ts.map +1 -0
- package/package.json +54 -94
- package/src/constants.tsx +4 -0
- package/src/index.tsx +4 -0
- package/src/types.tsx +122 -0
- package/src/utils/DrawerGestureContext.tsx +3 -0
- package/src/utils/DrawerProgressContext.tsx +6 -0
- package/src/utils/useDrawerProgress.tsx +18 -0
- package/src/views/Drawer.tsx +122 -0
- package/src/views/GestureHandler.android.tsx +1 -0
- package/src/views/GestureHandler.ios.tsx +1 -0
- package/src/views/GestureHandler.tsx +29 -0
- package/src/views/GestureHandlerNative.tsx +24 -0
- package/src/views/legacy/Drawer.tsx +682 -0
- package/src/views/legacy/Overlay.tsx +87 -0
- package/src/views/modern/Drawer.tsx +413 -0
- package/src/views/modern/Overlay.tsx +82 -0
- package/dist/DrawerLayout.js +0 -430
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
I18nManager,
|
|
4
|
+
Platform,
|
|
5
|
+
StyleProp,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
useWindowDimensions,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import * as Reanimated from 'react-native-reanimated';
|
|
11
|
+
|
|
12
|
+
import { SWIPE_MIN_DISTANCE, SWIPE_MIN_VELOCITY } from '../constants';
|
|
13
|
+
import type { DrawerProps } from '../types';
|
|
14
|
+
import { GestureHandlerRootView } from './GestureHandler';
|
|
15
|
+
|
|
16
|
+
type Props = DrawerProps & {
|
|
17
|
+
/**
|
|
18
|
+
* Whether to use the legacy implementation of the drawer.
|
|
19
|
+
* The legacy implementation uses v1 of Reanimated.
|
|
20
|
+
* The modern implementation uses v2 of Reanimated.
|
|
21
|
+
*
|
|
22
|
+
* By default, the appropriate implementation is used based on whether Reanimated v2 is configured.
|
|
23
|
+
*/
|
|
24
|
+
useLegacyImplementation?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Style object for the wrapper view.
|
|
28
|
+
*/
|
|
29
|
+
style?: StyleProp<ViewStyle>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getDefaultDrawerWidth = ({
|
|
33
|
+
height,
|
|
34
|
+
width,
|
|
35
|
+
}: {
|
|
36
|
+
height: number;
|
|
37
|
+
width: number;
|
|
38
|
+
}) => {
|
|
39
|
+
/*
|
|
40
|
+
* Default drawer width is screen width - header height
|
|
41
|
+
* with a max width of 280 on mobile and 320 on tablet
|
|
42
|
+
* https://material.io/components/navigation-drawer
|
|
43
|
+
*/
|
|
44
|
+
const smallerAxisSize = Math.min(height, width);
|
|
45
|
+
const isLandscape = width > height;
|
|
46
|
+
const isTablet = smallerAxisSize >= 600;
|
|
47
|
+
const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;
|
|
48
|
+
const maxWidth = isTablet ? 320 : 280;
|
|
49
|
+
|
|
50
|
+
return Math.min(smallerAxisSize - appBarHeight, maxWidth);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default function Drawer({
|
|
54
|
+
// Reanimated 2 is not configured
|
|
55
|
+
// @ts-expect-error: the type definitions are incomplete
|
|
56
|
+
useLegacyImplementation = !Reanimated.isConfigured?.(),
|
|
57
|
+
layout: customLayout,
|
|
58
|
+
drawerType = Platform.select({ ios: 'slide', default: 'front' }),
|
|
59
|
+
drawerPosition = I18nManager.getConstants().isRTL ? 'right' : 'left',
|
|
60
|
+
drawerStyle,
|
|
61
|
+
swipeEnabled = Platform.OS !== 'web' &&
|
|
62
|
+
Platform.OS !== 'windows' &&
|
|
63
|
+
Platform.OS !== 'macos',
|
|
64
|
+
swipeEdgeWidth = 32,
|
|
65
|
+
swipeMinDistance = SWIPE_MIN_DISTANCE,
|
|
66
|
+
swipeMinVelocity = SWIPE_MIN_VELOCITY,
|
|
67
|
+
keyboardDismissMode = 'on-drag',
|
|
68
|
+
hideStatusBarOnOpen = false,
|
|
69
|
+
statusBarAnimation = 'slide',
|
|
70
|
+
style,
|
|
71
|
+
...rest
|
|
72
|
+
}: Props) {
|
|
73
|
+
// Reanimated v3 dropped legacy v1 API
|
|
74
|
+
const legacyImplemenationNotAvailable =
|
|
75
|
+
require('react-native-reanimated').abs === undefined;
|
|
76
|
+
|
|
77
|
+
if (useLegacyImplementation && legacyImplemenationNotAvailable) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
'The `useLegacyImplementation` prop is not available with Reanimated 3 as it no longer includes support for Reanimated 1 legacy API. Remove the `useLegacyImplementation` prop from `Drawer.Navigator` to be able to use it.'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const Drawer: typeof import('./modern/Drawer').default =
|
|
84
|
+
useLegacyImplementation
|
|
85
|
+
? require('./legacy/Drawer').default
|
|
86
|
+
: require('./modern/Drawer').default;
|
|
87
|
+
|
|
88
|
+
const windowDimensions = useWindowDimensions();
|
|
89
|
+
const layout = customLayout ?? windowDimensions;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<GestureHandlerRootView style={[styles.container, style]}>
|
|
93
|
+
<Drawer
|
|
94
|
+
{...rest}
|
|
95
|
+
layout={layout}
|
|
96
|
+
drawerType={drawerType}
|
|
97
|
+
drawerPosition={drawerPosition}
|
|
98
|
+
drawerStyle={[
|
|
99
|
+
{ width: getDefaultDrawerWidth(layout) },
|
|
100
|
+
styles.drawer,
|
|
101
|
+
drawerStyle,
|
|
102
|
+
]}
|
|
103
|
+
swipeEnabled={swipeEnabled}
|
|
104
|
+
swipeEdgeWidth={swipeEdgeWidth}
|
|
105
|
+
swipeMinDistance={swipeMinDistance}
|
|
106
|
+
swipeMinVelocity={swipeMinVelocity}
|
|
107
|
+
keyboardDismissMode={keyboardDismissMode}
|
|
108
|
+
hideStatusBarOnOpen={hideStatusBarOnOpen}
|
|
109
|
+
statusBarAnimation={statusBarAnimation}
|
|
110
|
+
/>
|
|
111
|
+
</GestureHandlerRootView>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const styles = StyleSheet.create({
|
|
116
|
+
container: {
|
|
117
|
+
flex: 1,
|
|
118
|
+
},
|
|
119
|
+
drawer: {
|
|
120
|
+
backgroundColor: 'white',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GestureHandlerNative';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GestureHandlerNative';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
PanGestureHandlerProperties,
|
|
5
|
+
TapGestureHandlerProperties,
|
|
6
|
+
} from 'react-native-gesture-handler';
|
|
7
|
+
|
|
8
|
+
const Dummy: any = ({ children }: { children: React.ReactNode }) => (
|
|
9
|
+
<>{children}</>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const PanGestureHandler =
|
|
13
|
+
Dummy as React.ComponentType<PanGestureHandlerProperties>;
|
|
14
|
+
|
|
15
|
+
export const TapGestureHandler =
|
|
16
|
+
Dummy as React.ComponentType<TapGestureHandlerProperties>;
|
|
17
|
+
|
|
18
|
+
export const GestureHandlerRootView = View;
|
|
19
|
+
|
|
20
|
+
export const enum GestureState {
|
|
21
|
+
UNDETERMINED = 0,
|
|
22
|
+
FAILED = 1,
|
|
23
|
+
BEGAN = 2,
|
|
24
|
+
CANCELLED = 3,
|
|
25
|
+
ACTIVE = 4,
|
|
26
|
+
END = 5,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
PanGestureHandler as PanGestureHandlerNative,
|
|
4
|
+
PanGestureHandlerProperties,
|
|
5
|
+
} from 'react-native-gesture-handler';
|
|
6
|
+
|
|
7
|
+
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
|
8
|
+
|
|
9
|
+
export function PanGestureHandler(props: PanGestureHandlerProperties) {
|
|
10
|
+
const gestureRef = React.useRef<PanGestureHandlerNative>(null);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<DrawerGestureContext.Provider value={gestureRef}>
|
|
14
|
+
<PanGestureHandlerNative {...props} />
|
|
15
|
+
</DrawerGestureContext.Provider>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
|
|
20
|
+
export {
|
|
21
|
+
GestureHandlerRootView,
|
|
22
|
+
State as GestureState,
|
|
23
|
+
TapGestureHandler,
|
|
24
|
+
} from 'react-native-gesture-handler';
|