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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -35
  3. package/lib/commonjs/constants.js +15 -0
  4. package/lib/commonjs/constants.js.map +1 -0
  5. package/lib/commonjs/index.js +35 -0
  6. package/lib/commonjs/index.js.map +1 -0
  7. package/lib/commonjs/types.js +6 -0
  8. package/lib/commonjs/types.js.map +1 -0
  9. package/lib/commonjs/utils/DrawerGestureContext.js +12 -0
  10. package/lib/commonjs/utils/DrawerGestureContext.js.map +1 -0
  11. package/lib/commonjs/utils/DrawerProgressContext.js +12 -0
  12. package/lib/commonjs/utils/DrawerProgressContext.js.map +1 -0
  13. package/lib/commonjs/utils/useDrawerProgress.js +19 -0
  14. package/lib/commonjs/utils/useDrawerProgress.js.map +1 -0
  15. package/lib/commonjs/views/Drawer.js +89 -0
  16. package/lib/commonjs/views/Drawer.js.map +1 -0
  17. package/lib/commonjs/views/GestureHandler.android.js +17 -0
  18. package/lib/commonjs/views/GestureHandler.android.js.map +1 -0
  19. package/lib/commonjs/views/GestureHandler.ios.js +17 -0
  20. package/lib/commonjs/views/GestureHandler.ios.js.map +1 -0
  21. package/lib/commonjs/views/GestureHandler.js +33 -0
  22. package/lib/commonjs/views/GestureHandler.js.map +1 -0
  23. package/lib/commonjs/views/GestureHandlerNative.js +37 -0
  24. package/lib/commonjs/views/GestureHandlerNative.js.map +1 -0
  25. package/lib/commonjs/views/legacy/Drawer.js +419 -0
  26. package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
  27. package/lib/commonjs/views/legacy/Overlay.js +74 -0
  28. package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
  29. package/lib/commonjs/views/modern/Drawer.js +285 -0
  30. package/lib/commonjs/views/modern/Drawer.js.map +1 -0
  31. package/lib/commonjs/views/modern/Overlay.js +69 -0
  32. package/lib/commonjs/views/modern/Overlay.js.map +1 -0
  33. package/lib/module/constants.js +5 -0
  34. package/lib/module/constants.js.map +1 -0
  35. package/lib/module/index.js +5 -0
  36. package/lib/module/index.js.map +1 -0
  37. package/lib/module/types.js +2 -0
  38. package/lib/module/types.js.map +1 -0
  39. package/lib/module/utils/DrawerGestureContext.js +3 -0
  40. package/lib/module/utils/DrawerGestureContext.js.map +1 -0
  41. package/lib/module/utils/DrawerProgressContext.js +3 -0
  42. package/lib/module/utils/DrawerProgressContext.js.map +1 -0
  43. package/lib/module/utils/useDrawerProgress.js +10 -0
  44. package/lib/module/utils/useDrawerProgress.js.map +1 -0
  45. package/lib/module/views/Drawer.js +81 -0
  46. package/lib/module/views/Drawer.js.map +1 -0
  47. package/lib/module/views/GestureHandler.android.js +2 -0
  48. package/lib/module/views/GestureHandler.android.js.map +1 -0
  49. package/lib/module/views/GestureHandler.ios.js +2 -0
  50. package/lib/module/views/GestureHandler.ios.js.map +1 -0
  51. package/lib/module/views/GestureHandler.js +21 -0
  52. package/lib/module/views/GestureHandler.js.map +1 -0
  53. package/lib/module/views/GestureHandlerNative.js +11 -0
  54. package/lib/module/views/GestureHandlerNative.js.map +1 -0
  55. package/lib/module/views/legacy/Drawer.js +409 -0
  56. package/lib/module/views/legacy/Drawer.js.map +1 -0
  57. package/lib/module/views/legacy/Overlay.js +64 -0
  58. package/lib/module/views/legacy/Overlay.js.map +1 -0
  59. package/lib/module/views/modern/Drawer.js +276 -0
  60. package/lib/module/views/modern/Drawer.js.map +1 -0
  61. package/lib/module/views/modern/Overlay.js +60 -0
  62. package/lib/module/views/modern/Overlay.js.map +1 -0
  63. package/lib/typescript/src/constants.d.ts +5 -0
  64. package/lib/typescript/src/constants.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +5 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -0
  67. package/lib/typescript/src/types.d.ts +110 -0
  68. package/lib/typescript/src/types.d.ts.map +1 -0
  69. package/lib/typescript/src/utils/DrawerGestureContext.d.ts +4 -0
  70. package/lib/typescript/src/utils/DrawerGestureContext.d.ts.map +1 -0
  71. package/lib/typescript/src/utils/DrawerProgressContext.d.ts +5 -0
  72. package/lib/typescript/src/utils/DrawerProgressContext.d.ts.map +1 -0
  73. package/lib/typescript/src/utils/useDrawerProgress.d.ts +3 -0
  74. package/lib/typescript/src/utils/useDrawerProgress.d.ts.map +1 -0
  75. package/lib/typescript/src/views/Drawer.d.ts +20 -0
  76. package/lib/typescript/src/views/Drawer.d.ts.map +1 -0
  77. package/lib/typescript/src/views/GestureHandler.android.d.ts +2 -0
  78. package/lib/typescript/src/views/GestureHandler.android.d.ts.map +1 -0
  79. package/lib/typescript/src/views/GestureHandler.d.ts +15 -0
  80. package/lib/typescript/src/views/GestureHandler.d.ts.map +1 -0
  81. package/lib/typescript/src/views/GestureHandler.ios.d.ts +2 -0
  82. package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +1 -0
  83. package/lib/typescript/src/views/GestureHandlerNative.d.ts +6 -0
  84. package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -0
  85. package/lib/typescript/src/views/legacy/Drawer.d.ts +51 -0
  86. package/lib/typescript/src/views/legacy/Drawer.d.ts.map +1 -0
  87. package/lib/typescript/src/views/legacy/Overlay.d.ts +89 -0
  88. package/lib/typescript/src/views/legacy/Overlay.d.ts.map +1 -0
  89. package/lib/typescript/src/views/modern/Drawer.d.ts +10 -0
  90. package/lib/typescript/src/views/modern/Drawer.d.ts.map +1 -0
  91. package/lib/typescript/src/views/modern/Overlay.d.ts +89 -0
  92. package/lib/typescript/src/views/modern/Overlay.d.ts.map +1 -0
  93. package/package.json +54 -94
  94. package/src/constants.tsx +4 -0
  95. package/src/index.tsx +4 -0
  96. package/src/types.tsx +122 -0
  97. package/src/utils/DrawerGestureContext.tsx +3 -0
  98. package/src/utils/DrawerProgressContext.tsx +6 -0
  99. package/src/utils/useDrawerProgress.tsx +18 -0
  100. package/src/views/Drawer.tsx +122 -0
  101. package/src/views/GestureHandler.android.tsx +1 -0
  102. package/src/views/GestureHandler.ios.tsx +1 -0
  103. package/src/views/GestureHandler.tsx +29 -0
  104. package/src/views/GestureHandlerNative.tsx +24 -0
  105. package/src/views/legacy/Drawer.tsx +682 -0
  106. package/src/views/legacy/Overlay.tsx +87 -0
  107. package/src/views/modern/Drawer.tsx +413 -0
  108. package/src/views/modern/Overlay.tsx +82 -0
  109. 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';