@react-navigation/drawer 6.5.8 → 7.0.0-alpha.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 (120) hide show
  1. package/lib/commonjs/index.js +4 -6
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/navigators/createDrawerNavigator.js +3 -43
  4. package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -1
  5. package/lib/commonjs/views/DrawerItem.js +13 -5
  6. package/lib/commonjs/views/DrawerItem.js.map +1 -1
  7. package/lib/commonjs/views/DrawerItemList.js +6 -6
  8. package/lib/commonjs/views/DrawerItemList.js.map +1 -1
  9. package/lib/commonjs/views/DrawerView.js +23 -58
  10. package/lib/commonjs/views/DrawerView.js.map +1 -1
  11. package/lib/module/index.js +1 -3
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/navigators/createDrawerNavigator.js +3 -43
  14. package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
  15. package/lib/module/views/DrawerItem.js +14 -6
  16. package/lib/module/views/DrawerItem.js.map +1 -1
  17. package/lib/module/views/DrawerItemList.js +7 -7
  18. package/lib/module/views/DrawerItemList.js.map +1 -1
  19. package/lib/module/views/DrawerView.js +23 -58
  20. package/lib/module/views/DrawerView.js.map +1 -1
  21. package/lib/typescript/src/index.d.ts +1 -3
  22. package/lib/typescript/src/index.d.ts.map +1 -1
  23. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +8 -3
  24. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts.map +1 -1
  25. package/lib/typescript/src/types.d.ts +20 -14
  26. package/lib/typescript/src/types.d.ts.map +1 -1
  27. package/lib/typescript/src/views/DrawerItem.d.ts +18 -5
  28. package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
  29. package/lib/typescript/src/views/DrawerItemList.d.ts +1 -1
  30. package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
  31. package/lib/typescript/src/views/DrawerToggleButton.d.ts +1 -1
  32. package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
  33. package/lib/typescript/src/views/DrawerView.d.ts +1 -1
  34. package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
  35. package/lib/typescript/src/views/ScreenFallback.d.ts +1 -1
  36. package/lib/typescript/src/views/ScreenFallback.d.ts.map +1 -1
  37. package/package.json +14 -14
  38. package/src/index.tsx +5 -3
  39. package/src/navigators/createDrawerNavigator.tsx +2 -72
  40. package/src/types.tsx +8 -1
  41. package/src/views/DrawerItem.tsx +33 -11
  42. package/src/views/DrawerItemList.tsx +5 -4
  43. package/src/views/DrawerView.tsx +17 -68
  44. package/lib/commonjs/utils/DrawerGestureContext.js +0 -12
  45. package/lib/commonjs/utils/DrawerGestureContext.js.map +0 -1
  46. package/lib/commonjs/utils/DrawerProgressContext.js +0 -12
  47. package/lib/commonjs/utils/DrawerProgressContext.js.map +0 -1
  48. package/lib/commonjs/utils/useDrawerProgress.js +0 -19
  49. package/lib/commonjs/utils/useDrawerProgress.js.map +0 -1
  50. package/lib/commonjs/views/GestureHandler.android.js +0 -17
  51. package/lib/commonjs/views/GestureHandler.android.js.map +0 -1
  52. package/lib/commonjs/views/GestureHandler.ios.js +0 -17
  53. package/lib/commonjs/views/GestureHandler.ios.js.map +0 -1
  54. package/lib/commonjs/views/GestureHandler.js +0 -32
  55. package/lib/commonjs/views/GestureHandler.js.map +0 -1
  56. package/lib/commonjs/views/GestureHandlerNative.js +0 -37
  57. package/lib/commonjs/views/GestureHandlerNative.js.map +0 -1
  58. package/lib/commonjs/views/legacy/Drawer.js +0 -419
  59. package/lib/commonjs/views/legacy/Drawer.js.map +0 -1
  60. package/lib/commonjs/views/legacy/Overlay.js +0 -71
  61. package/lib/commonjs/views/legacy/Overlay.js.map +0 -1
  62. package/lib/commonjs/views/modern/Drawer.js +0 -303
  63. package/lib/commonjs/views/modern/Drawer.js.map +0 -1
  64. package/lib/commonjs/views/modern/Overlay.js +0 -66
  65. package/lib/commonjs/views/modern/Overlay.js.map +0 -1
  66. package/lib/module/utils/DrawerGestureContext.js +0 -3
  67. package/lib/module/utils/DrawerGestureContext.js.map +0 -1
  68. package/lib/module/utils/DrawerProgressContext.js +0 -3
  69. package/lib/module/utils/DrawerProgressContext.js.map +0 -1
  70. package/lib/module/utils/useDrawerProgress.js +0 -10
  71. package/lib/module/utils/useDrawerProgress.js.map +0 -1
  72. package/lib/module/views/GestureHandler.android.js +0 -2
  73. package/lib/module/views/GestureHandler.android.js.map +0 -1
  74. package/lib/module/views/GestureHandler.ios.js +0 -2
  75. package/lib/module/views/GestureHandler.ios.js.map +0 -1
  76. package/lib/module/views/GestureHandler.js +0 -20
  77. package/lib/module/views/GestureHandler.js.map +0 -1
  78. package/lib/module/views/GestureHandlerNative.js +0 -11
  79. package/lib/module/views/GestureHandlerNative.js.map +0 -1
  80. package/lib/module/views/legacy/Drawer.js +0 -409
  81. package/lib/module/views/legacy/Drawer.js.map +0 -1
  82. package/lib/module/views/legacy/Overlay.js +0 -61
  83. package/lib/module/views/legacy/Overlay.js.map +0 -1
  84. package/lib/module/views/modern/Drawer.js +0 -294
  85. package/lib/module/views/modern/Drawer.js.map +0 -1
  86. package/lib/module/views/modern/Overlay.js +0 -57
  87. package/lib/module/views/modern/Overlay.js.map +0 -1
  88. package/lib/typescript/src/utils/DrawerGestureContext.d.ts +0 -4
  89. package/lib/typescript/src/utils/DrawerGestureContext.d.ts.map +0 -1
  90. package/lib/typescript/src/utils/DrawerProgressContext.d.ts +0 -5
  91. package/lib/typescript/src/utils/DrawerProgressContext.d.ts.map +0 -1
  92. package/lib/typescript/src/utils/useDrawerProgress.d.ts +0 -3
  93. package/lib/typescript/src/utils/useDrawerProgress.d.ts.map +0 -1
  94. package/lib/typescript/src/views/GestureHandler.android.d.ts +0 -2
  95. package/lib/typescript/src/views/GestureHandler.android.d.ts.map +0 -1
  96. package/lib/typescript/src/views/GestureHandler.d.ts +0 -15
  97. package/lib/typescript/src/views/GestureHandler.d.ts.map +0 -1
  98. package/lib/typescript/src/views/GestureHandler.ios.d.ts +0 -2
  99. package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +0 -1
  100. package/lib/typescript/src/views/GestureHandlerNative.d.ts +0 -6
  101. package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +0 -1
  102. package/lib/typescript/src/views/legacy/Drawer.d.ts +0 -45
  103. package/lib/typescript/src/views/legacy/Drawer.d.ts.map +0 -1
  104. package/lib/typescript/src/views/legacy/Overlay.d.ts +0 -74
  105. package/lib/typescript/src/views/legacy/Overlay.d.ts.map +0 -1
  106. package/lib/typescript/src/views/modern/Drawer.d.ts +0 -4
  107. package/lib/typescript/src/views/modern/Drawer.d.ts.map +0 -1
  108. package/lib/typescript/src/views/modern/Overlay.d.ts +0 -74
  109. package/lib/typescript/src/views/modern/Overlay.d.ts.map +0 -1
  110. package/src/utils/DrawerGestureContext.tsx +0 -3
  111. package/src/utils/DrawerProgressContext.tsx +0 -6
  112. package/src/utils/useDrawerProgress.tsx +0 -18
  113. package/src/views/GestureHandler.android.tsx +0 -1
  114. package/src/views/GestureHandler.ios.tsx +0 -1
  115. package/src/views/GestureHandler.tsx +0 -29
  116. package/src/views/GestureHandlerNative.tsx +0 -24
  117. package/src/views/legacy/Drawer.tsx +0 -671
  118. package/src/views/legacy/Overlay.tsx +0 -75
  119. package/src/views/modern/Drawer.tsx +0 -424
  120. package/src/views/modern/Overlay.tsx +0 -70
@@ -1,75 +0,0 @@
1
- import * as React from 'react';
2
- import { Platform, Pressable, StyleSheet } from 'react-native';
3
- import Animated from 'react-native-reanimated';
4
-
5
- const {
6
- // @ts-expect-error: this is to support reanimated 1
7
- interpolate: interpolateDeprecated,
8
- interpolateNode,
9
- cond,
10
- greaterThan,
11
- } = Animated;
12
-
13
- const interpolate: typeof interpolateNode =
14
- interpolateNode ?? interpolateDeprecated;
15
-
16
- const PROGRESS_EPSILON = 0.05;
17
-
18
- type Props = React.ComponentProps<typeof Animated.View> & {
19
- progress: Animated.Node<number>;
20
- onPress: () => void;
21
- };
22
-
23
- const Overlay = React.forwardRef(function Overlay(
24
- { progress, onPress, style, ...props }: Props,
25
- ref: React.Ref<Animated.View>
26
- ) {
27
- const animatedStyle = {
28
- opacity: interpolate(progress, {
29
- // Default input range is [PROGRESS_EPSILON, 1]
30
- // On Windows, the output value is 1 when input value is out of range for some reason
31
- // The default value 0 will be interpolated to 1 in this case, which is not what we want.
32
- // Therefore changing input range on Windows to [0,1] instead.
33
- inputRange:
34
- Platform.OS === 'windows' || Platform.OS === 'macos'
35
- ? [0, 1]
36
- : [PROGRESS_EPSILON, 1],
37
- outputRange: [0, 1],
38
- }),
39
- // We don't want the user to be able to press through the overlay when drawer is open
40
- // One approach is to adjust the pointerEvents based on the progress
41
- // But we can also send the overlay behind the screen, which works, and is much less code
42
- zIndex: cond(greaterThan(progress, PROGRESS_EPSILON), 0, -1),
43
- };
44
-
45
- return (
46
- <Animated.View
47
- {...props}
48
- ref={ref}
49
- style={[styles.overlay, overlayStyle, animatedStyle, style]}
50
- >
51
- <Pressable onPress={onPress} style={styles.pressable} />
52
- </Animated.View>
53
- );
54
- });
55
-
56
- const overlayStyle = Platform.select<Record<string, string>>({
57
- web: {
58
- // Disable touch highlight on mobile Safari.
59
- // WebkitTapHighlightColor must be used outside of StyleSheet.create because react-native-web will omit the property.
60
- WebkitTapHighlightColor: 'transparent',
61
- },
62
- default: {},
63
- });
64
-
65
- const styles = StyleSheet.create({
66
- overlay: {
67
- ...StyleSheet.absoluteFillObject,
68
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
69
- },
70
- pressable: {
71
- flex: 1,
72
- },
73
- });
74
-
75
- export default Overlay;
@@ -1,424 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- I18nManager,
4
- InteractionManager,
5
- Keyboard,
6
- Platform,
7
- StatusBar,
8
- StyleSheet,
9
- View,
10
- } from 'react-native';
11
- import {
12
- PanGestureHandler,
13
- PanGestureHandlerGestureEvent,
14
- State as GestureState,
15
- } from 'react-native-gesture-handler';
16
- import Animated, {
17
- interpolate,
18
- runOnJS,
19
- useAnimatedGestureHandler,
20
- useAnimatedStyle,
21
- useDerivedValue,
22
- useSharedValue,
23
- withSpring,
24
- } from 'react-native-reanimated';
25
-
26
- import type { DrawerProps } from '../../types';
27
- import DrawerProgressContext from '../../utils/DrawerProgressContext';
28
- import Overlay from './Overlay';
29
-
30
- const SWIPE_DISTANCE_MINIMUM = 5;
31
- const DEFAULT_DRAWER_WIDTH = '80%';
32
-
33
- type ToggleOptions = {
34
- open: boolean;
35
- isUserInitiated: boolean;
36
- velocity?: number;
37
- };
38
-
39
- const minmax = (value: number, start: number, end: number) => {
40
- 'worklet';
41
-
42
- return Math.min(Math.max(value, start), end);
43
- };
44
-
45
- export default function Drawer({
46
- dimensions,
47
- drawerPosition,
48
- drawerStyle,
49
- drawerType,
50
- gestureHandlerProps,
51
- hideStatusBarOnOpen,
52
- keyboardDismissMode,
53
- onClose,
54
- onOpen,
55
- open,
56
- overlayStyle,
57
- renderDrawerContent,
58
- renderSceneContent,
59
- statusBarAnimation,
60
- swipeDistanceThreshold,
61
- swipeEdgeWidth,
62
- swipeEnabled,
63
- swipeVelocityThreshold,
64
- }: DrawerProps) {
65
- const getDrawerWidth = (): number => {
66
- const { width = DEFAULT_DRAWER_WIDTH } =
67
- StyleSheet.flatten(drawerStyle) || {};
68
-
69
- if (typeof width === 'string' && width.endsWith('%')) {
70
- // Try to calculate width if a percentage is given
71
- const percentage = Number(width.replace(/%$/, ''));
72
-
73
- if (Number.isFinite(percentage)) {
74
- return dimensions.width * (percentage / 100);
75
- }
76
- }
77
-
78
- return typeof width === 'number' ? width : 0;
79
- };
80
-
81
- const drawerWidth = getDrawerWidth();
82
-
83
- const isOpen = drawerType === 'permanent' ? true : open;
84
- const isRight = drawerPosition === 'right';
85
-
86
- const getDrawerTranslationX = React.useCallback(
87
- (open: boolean) => {
88
- 'worklet';
89
-
90
- if (drawerPosition === 'left') {
91
- return open ? 0 : -drawerWidth;
92
- }
93
-
94
- return open ? 0 : drawerWidth;
95
- },
96
- [drawerPosition, drawerWidth]
97
- );
98
-
99
- const hideStatusBar = React.useCallback(
100
- (hide: boolean) => {
101
- if (hideStatusBarOnOpen) {
102
- StatusBar.setHidden(hide, statusBarAnimation);
103
- }
104
- },
105
- [hideStatusBarOnOpen, statusBarAnimation]
106
- );
107
-
108
- React.useEffect(() => {
109
- hideStatusBar(isOpen);
110
-
111
- return () => hideStatusBar(false);
112
- }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);
113
-
114
- const interactionHandleRef = React.useRef<number | null>(null);
115
-
116
- const startInteraction = () => {
117
- interactionHandleRef.current = InteractionManager.createInteractionHandle();
118
- };
119
-
120
- const endInteraction = () => {
121
- if (interactionHandleRef.current != null) {
122
- InteractionManager.clearInteractionHandle(interactionHandleRef.current);
123
- interactionHandleRef.current = null;
124
- }
125
- };
126
-
127
- const hideKeyboard = () => {
128
- if (keyboardDismissMode === 'on-drag') {
129
- Keyboard.dismiss();
130
- }
131
- };
132
-
133
- const onGestureStart = () => {
134
- startInteraction();
135
- hideKeyboard();
136
- hideStatusBar(true);
137
- };
138
-
139
- const onGestureFinish = () => {
140
- endInteraction();
141
- };
142
-
143
- // FIXME: Currently hitSlop is broken when on Android when drawer is on right
144
- // https://github.com/software-mansion/react-native-gesture-handler/issues/569
145
- const hitSlop = isRight
146
- ? // Extend hitSlop to the side of the screen when drawer is closed
147
- // This lets the user drag the drawer from the side of the screen
148
- { right: 0, width: isOpen ? undefined : swipeEdgeWidth }
149
- : { left: 0, width: isOpen ? undefined : swipeEdgeWidth };
150
-
151
- const touchStartX = useSharedValue(0);
152
- const touchX = useSharedValue(0);
153
- const translationX = useSharedValue(getDrawerTranslationX(open));
154
- const gestureState = useSharedValue<GestureState>(GestureState.UNDETERMINED);
155
-
156
- const toggleDrawer = React.useCallback(
157
- ({ open, isUserInitiated, velocity }: ToggleOptions) => {
158
- 'worklet';
159
-
160
- const translateX = getDrawerTranslationX(open);
161
-
162
- touchStartX.value = 0;
163
- touchX.value = 0;
164
- translationX.value = withSpring(translateX, {
165
- velocity,
166
- stiffness: 1000,
167
- damping: 500,
168
- mass: 3,
169
- overshootClamping: true,
170
- restDisplacementThreshold: 0.01,
171
- restSpeedThreshold: 0.01,
172
- });
173
-
174
- if (!isUserInitiated) {
175
- return;
176
- }
177
-
178
- if (open) {
179
- runOnJS(onOpen)();
180
- } else {
181
- runOnJS(onClose)();
182
- }
183
- },
184
- [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]
185
- );
186
-
187
- React.useEffect(
188
- () => toggleDrawer({ open, isUserInitiated: false }),
189
- [open, toggleDrawer]
190
- );
191
-
192
- const onGestureEvent = useAnimatedGestureHandler<
193
- PanGestureHandlerGestureEvent,
194
- { startX: number; hasCalledOnStart: boolean }
195
- >({
196
- onStart: (event, ctx) => {
197
- ctx.hasCalledOnStart = false;
198
- ctx.startX = translationX.value;
199
- gestureState.value = event.state;
200
- touchStartX.value = event.x;
201
- },
202
- onActive: (event, ctx) => {
203
- touchX.value = event.x;
204
- translationX.value = ctx.startX + event.translationX;
205
- gestureState.value = event.state;
206
-
207
- // onStart will _always_ be called, even when the activation
208
- // criteria isn't met yet. This makes sure onGestureStart is only
209
- // called when the criteria is really met.
210
- if (!ctx.hasCalledOnStart) {
211
- ctx.hasCalledOnStart = true;
212
- runOnJS(onGestureStart)();
213
- }
214
- },
215
- onEnd: (event) => {
216
- gestureState.value = event.state;
217
-
218
- const nextOpen =
219
- (Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM &&
220
- Math.abs(event.translationX) > swipeVelocityThreshold) ||
221
- Math.abs(event.translationX) > swipeDistanceThreshold
222
- ? drawerPosition === 'left'
223
- ? // If swiped to right, open the drawer, otherwise close it
224
- (event.velocityX === 0 ? event.translationX : event.velocityX) > 0
225
- : // If swiped to left, open the drawer, otherwise close it
226
- (event.velocityX === 0 ? event.translationX : event.velocityX) < 0
227
- : open;
228
-
229
- toggleDrawer({
230
- open: nextOpen,
231
- isUserInitiated: true,
232
- velocity: event.velocityX,
233
- });
234
- },
235
- onFinish: () => {
236
- runOnJS(onGestureFinish)();
237
- },
238
- });
239
-
240
- const translateX = useDerivedValue(() => {
241
- // Comment stolen from react-native-gesture-handler/DrawerLayout
242
- //
243
- // While closing the drawer when user starts gesture outside of its area (in greyed
244
- // out part of the window), we want the drawer to follow only once finger reaches the
245
- // edge of the drawer.
246
- // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by
247
- // dots. The touch gesture starts at '*' and moves left, touch path is indicated by
248
- // an arrow pointing left
249
- // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+
250
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
251
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
252
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
253
- // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|
254
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
255
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
256
- // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
257
- // +---------------+ +---------------+ +---------------+ +---------------+
258
- //
259
- // For the above to work properly we define animated value that will keep start position
260
- // of the gesture. Then we use that value to calculate how much we need to subtract from
261
- // the translationX. If the gesture started on the greyed out area we take the distance from the
262
- // edge of the drawer to the start position. Otherwise we don't subtract at all and the
263
- // drawer be pulled back as soon as you start the pan.
264
- //
265
- // This is used only when drawerType is "front"
266
- const touchDistance =
267
- drawerType === 'front' && gestureState.value === GestureState.ACTIVE
268
- ? minmax(
269
- drawerPosition === 'left'
270
- ? touchStartX.value - drawerWidth
271
- : dimensions.width - drawerWidth - touchStartX.value,
272
- 0,
273
- dimensions.width
274
- )
275
- : 0;
276
-
277
- const translateX =
278
- drawerPosition === 'left'
279
- ? minmax(translationX.value + touchDistance, -drawerWidth, 0)
280
- : minmax(translationX.value - touchDistance, 0, drawerWidth);
281
-
282
- return translateX;
283
- });
284
-
285
- const isRTL = I18nManager.getConstants().isRTL;
286
- const drawerAnimatedStyle = useAnimatedStyle(() => {
287
- const distanceFromEdge = dimensions.width - drawerWidth;
288
-
289
- return {
290
- transform:
291
- drawerType === 'permanent'
292
- ? // Reanimated needs the property to be present, but it results in Browser bug
293
- // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
294
- []
295
- : [
296
- {
297
- translateX:
298
- // The drawer stays in place when `drawerType` is `back`
299
- (drawerType === 'back' ? 0 : translateX.value) +
300
- (drawerPosition === 'left'
301
- ? isRTL
302
- ? -distanceFromEdge
303
- : 0
304
- : isRTL
305
- ? 0
306
- : distanceFromEdge),
307
- },
308
- ],
309
- };
310
- });
311
-
312
- const contentAnimatedStyle = useAnimatedStyle(() => {
313
- return {
314
- transform:
315
- drawerType === 'permanent'
316
- ? // Reanimated needs the property to be present, but it results in Browser bug
317
- // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
318
- []
319
- : [
320
- {
321
- translateX:
322
- // The screen content stays in place when `drawerType` is `front`
323
- drawerType === 'front'
324
- ? 0
325
- : translateX.value +
326
- drawerWidth * (drawerPosition === 'left' ? 1 : -1),
327
- },
328
- ],
329
- };
330
- });
331
-
332
- const progress = useDerivedValue(() => {
333
- return drawerType === 'permanent'
334
- ? 1
335
- : interpolate(
336
- translateX.value,
337
- [getDrawerTranslationX(false), getDrawerTranslationX(true)],
338
- [0, 1]
339
- );
340
- });
341
-
342
- return (
343
- <DrawerProgressContext.Provider value={progress}>
344
- <PanGestureHandler
345
- activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
346
- failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
347
- hitSlop={hitSlop}
348
- enabled={drawerType !== 'permanent' && swipeEnabled}
349
- onGestureEvent={onGestureEvent}
350
- {...gestureHandlerProps}
351
- >
352
- {/* Immediate child of gesture handler needs to be an Animated.View */}
353
- <Animated.View
354
- style={[
355
- styles.main,
356
- {
357
- flexDirection:
358
- drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row',
359
- },
360
- ]}
361
- >
362
- <Animated.View style={[styles.content, contentAnimatedStyle]}>
363
- <View
364
- accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}
365
- importantForAccessibility={
366
- isOpen && drawerType !== 'permanent'
367
- ? 'no-hide-descendants'
368
- : 'auto'
369
- }
370
- style={styles.content}
371
- >
372
- {renderSceneContent()}
373
- </View>
374
- {drawerType !== 'permanent' ? (
375
- <Overlay
376
- progress={progress}
377
- onPress={() =>
378
- toggleDrawer({ open: false, isUserInitiated: true })
379
- }
380
- style={overlayStyle}
381
- />
382
- ) : null}
383
- </Animated.View>
384
- <Animated.View
385
- accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}
386
- removeClippedSubviews={Platform.OS !== 'ios'}
387
- style={[
388
- styles.container,
389
- {
390
- position: drawerType === 'permanent' ? 'relative' : 'absolute',
391
- zIndex: drawerType === 'back' ? -1 : 0,
392
- },
393
- drawerAnimatedStyle,
394
- drawerStyle as any,
395
- ]}
396
- >
397
- {renderDrawerContent()}
398
- </Animated.View>
399
- </Animated.View>
400
- </PanGestureHandler>
401
- </DrawerProgressContext.Provider>
402
- );
403
- }
404
-
405
- const styles = StyleSheet.create({
406
- container: {
407
- top: 0,
408
- bottom: 0,
409
- maxWidth: '100%',
410
- width: DEFAULT_DRAWER_WIDTH,
411
- },
412
- content: {
413
- flex: 1,
414
- },
415
- main: {
416
- flex: 1,
417
- ...Platform.select({
418
- // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.
419
- // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.
420
- web: null,
421
- default: { overflow: 'hidden' },
422
- }),
423
- },
424
- });
@@ -1,70 +0,0 @@
1
- import * as React from 'react';
2
- import { Platform, Pressable, StyleSheet } from 'react-native';
3
- import Animated, {
4
- useAnimatedProps,
5
- useAnimatedStyle,
6
- } from 'react-native-reanimated';
7
-
8
- const PROGRESS_EPSILON = 0.05;
9
-
10
- type Props = React.ComponentProps<typeof Animated.View> & {
11
- progress: Animated.SharedValue<number>;
12
- onPress: () => void;
13
- };
14
-
15
- const Overlay = React.forwardRef(function Overlay(
16
- { progress, onPress, style, ...props }: Props,
17
- ref: React.Ref<Animated.View>
18
- ) {
19
- const animatedStyle = useAnimatedStyle(() => {
20
- return {
21
- opacity: progress.value,
22
- // We don't want the user to be able to press through the overlay when drawer is open
23
- // We can send the overlay behind the screen to avoid it
24
- zIndex: progress.value > PROGRESS_EPSILON ? 0 : -1,
25
- };
26
- });
27
-
28
- const animatedProps = useAnimatedProps(() => {
29
- const active = progress.value > PROGRESS_EPSILON;
30
-
31
- return {
32
- pointerEvents: active ? 'auto' : 'none',
33
- accessibilityElementsHidden: !active,
34
- importantForAccessibility: active ? 'auto' : 'no-hide-descendants',
35
- } as const;
36
- });
37
-
38
- return (
39
- <Animated.View
40
- {...props}
41
- ref={ref}
42
- style={[styles.overlay, overlayStyle, animatedStyle, style]}
43
- animatedProps={animatedProps}
44
- >
45
- <Pressable onPress={onPress} style={styles.pressable} />
46
- </Animated.View>
47
- );
48
- });
49
-
50
- const overlayStyle = Platform.select<Record<string, string>>({
51
- web: {
52
- // Disable touch highlight on mobile Safari.
53
- // WebkitTapHighlightColor must be used outside of StyleSheet.create because react-native-web will omit the property.
54
- WebkitTapHighlightColor: 'transparent',
55
- },
56
- default: {},
57
- });
58
-
59
- const styles = StyleSheet.create({
60
- overlay: {
61
- ...StyleSheet.absoluteFillObject,
62
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
63
- },
64
- pressable: {
65
- flex: 1,
66
- pointerEvents: 'auto',
67
- },
68
- });
69
-
70
- export default Overlay;