react-native-drawer-layout 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (61) hide show
  1. package/lib/commonjs/utils/getDrawerWidth.js +42 -0
  2. package/lib/commonjs/utils/getDrawerWidth.js.map +1 -0
  3. package/lib/commonjs/utils/useDrawerProgress.js.map +1 -1
  4. package/lib/commonjs/utils/useFakeSharedValue.js +46 -0
  5. package/lib/commonjs/utils/useFakeSharedValue.js.map +1 -0
  6. package/lib/commonjs/views/Drawer.js +59 -269
  7. package/lib/commonjs/views/Drawer.js.map +1 -1
  8. package/lib/commonjs/views/Drawer.native.js +324 -0
  9. package/lib/commonjs/views/Drawer.native.js.map +1 -0
  10. package/lib/commonjs/views/Overlay.js +22 -39
  11. package/lib/commonjs/views/Overlay.js.map +1 -1
  12. package/lib/commonjs/views/Overlay.native.js +58 -0
  13. package/lib/commonjs/views/Overlay.native.js.map +1 -0
  14. package/lib/module/utils/getDrawerWidth.js +36 -0
  15. package/lib/module/utils/getDrawerWidth.js.map +1 -0
  16. package/lib/module/utils/useDrawerProgress.js.map +1 -1
  17. package/lib/module/utils/useFakeSharedValue.js +38 -0
  18. package/lib/module/utils/useFakeSharedValue.js.map +1 -0
  19. package/lib/module/views/Drawer.js +60 -270
  20. package/lib/module/views/Drawer.js.map +1 -1
  21. package/lib/module/views/Drawer.native.js +315 -0
  22. package/lib/module/views/Drawer.native.js.map +1 -0
  23. package/lib/module/views/Overlay.js +22 -39
  24. package/lib/module/views/Overlay.js.map +1 -1
  25. package/lib/module/views/Overlay.native.js +50 -0
  26. package/lib/module/views/Overlay.native.js.map +1 -0
  27. package/lib/typescript/src/types.d.ts +9 -2
  28. package/lib/typescript/src/types.d.ts.map +1 -1
  29. package/lib/typescript/src/utils/DrawerProgressContext.d.ts +2 -2
  30. package/lib/typescript/src/utils/DrawerProgressContext.d.ts.map +1 -1
  31. package/lib/typescript/src/utils/getDrawerWidth.d.ts +9 -0
  32. package/lib/typescript/src/utils/getDrawerWidth.d.ts.map +1 -0
  33. package/lib/typescript/src/utils/useDrawerProgress.d.ts +2 -2
  34. package/lib/typescript/src/utils/useDrawerProgress.d.ts.map +1 -1
  35. package/lib/typescript/src/utils/useFakeSharedValue.d.ts +17 -0
  36. package/lib/typescript/src/utils/useFakeSharedValue.d.ts.map +1 -0
  37. package/lib/typescript/src/views/Drawer.d.ts +1 -1
  38. package/lib/typescript/src/views/Drawer.d.ts.map +1 -1
  39. package/lib/typescript/src/views/Drawer.native.d.ts +4 -0
  40. package/lib/typescript/src/views/Drawer.native.d.ts.map +1 -0
  41. package/lib/typescript/src/views/Overlay.d.ts +2 -204
  42. package/lib/typescript/src/views/Overlay.d.ts.map +1 -1
  43. package/lib/typescript/src/views/Overlay.native.d.ts +4 -0
  44. package/lib/typescript/src/views/Overlay.native.d.ts.map +1 -0
  45. package/package.json +2 -2
  46. package/src/types.tsx +10 -1
  47. package/src/utils/DrawerProgressContext.tsx +2 -2
  48. package/src/utils/getDrawerWidth.tsx +49 -0
  49. package/src/utils/useDrawerProgress.tsx +2 -2
  50. package/src/utils/useFakeSharedValue.tsx +49 -0
  51. package/src/views/Drawer.native.tsx +466 -0
  52. package/src/views/Drawer.tsx +117 -418
  53. package/src/views/Overlay.native.tsx +63 -0
  54. package/src/views/Overlay.tsx +26 -59
  55. package/lib/commonjs/constants.js +0 -11
  56. package/lib/commonjs/constants.js.map +0 -1
  57. package/lib/module/constants.js +0 -5
  58. package/lib/module/constants.js.map +0 -1
  59. package/lib/typescript/src/constants.d.ts +0 -5
  60. package/lib/typescript/src/constants.d.ts.map +0 -1
  61. package/src/constants.tsx +0 -4
@@ -1,80 +1,47 @@
1
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';
2
+ import { Pressable, StyleSheet, View } from 'react-native';
7
3
 
8
- const PROGRESS_EPSILON = 0.05;
9
-
10
- type Props = React.ComponentProps<typeof Animated.View> & {
11
- progress: Animated.SharedValue<number>;
12
- onPress: () => void;
13
- accessibilityLabel?: string;
14
- };
15
-
16
- export const Overlay = React.forwardRef(function Overlay(
17
- {
18
- progress,
19
- onPress,
20
- style,
21
- accessibilityLabel = 'Close drawer',
22
- ...props
23
- }: Props,
24
- ref: React.Ref<Animated.View>
25
- ) {
26
- const animatedStyle = useAnimatedStyle(() => {
27
- return {
28
- opacity: progress.value,
29
- // We don't want the user to be able to press through the overlay when drawer is open
30
- // We can send the overlay behind the screen to avoid it
31
- zIndex: progress.value > PROGRESS_EPSILON ? 0 : -1,
32
- };
33
- });
34
-
35
- const animatedProps = useAnimatedProps(() => {
36
- const active = progress.value > PROGRESS_EPSILON;
37
-
38
- return {
39
- pointerEvents: active ? 'auto' : 'none',
40
- accessibilityElementsHidden: !active,
41
- importantForAccessibility: active ? 'auto' : 'no-hide-descendants',
42
- } as const;
43
- });
4
+ import type { OverlayProps } from '../types';
44
5
 
6
+ export function Overlay({
7
+ open,
8
+ onPress,
9
+ style,
10
+ accessibilityLabel = 'Close drawer',
11
+ ...rest
12
+ }: OverlayProps) {
45
13
  return (
46
- <Animated.View
47
- {...props}
48
- ref={ref}
49
- style={[styles.overlay, overlayStyle, animatedStyle, style]}
50
- animatedProps={animatedProps}
14
+ <View
15
+ {...rest}
16
+ style={[
17
+ styles.overlay,
18
+ { opacity: open ? 1 : 0, pointerEvents: open ? 'auto' : 'none' },
19
+ style,
20
+ ]}
21
+ accessibilityElementsHidden={!open}
22
+ importantForAccessibility={open ? 'auto' : 'no-hide-descendants'}
51
23
  >
52
24
  <Pressable
53
25
  onPress={onPress}
54
- style={styles.pressable}
26
+ style={[styles.pressable, { pointerEvents: open ? 'auto' : 'none' }]}
55
27
  accessibilityRole="button"
56
28
  accessibilityLabel={accessibilityLabel}
57
29
  />
58
- </Animated.View>
30
+ </View>
59
31
  );
60
- });
61
-
62
- const overlayStyle = Platform.select<Record<string, string>>({
63
- web: {
64
- // Disable touch highlight on mobile Safari.
65
- // WebkitTapHighlightColor must be used outside of StyleSheet.create because react-native-web will omit the property.
66
- WebkitTapHighlightColor: 'transparent',
67
- },
68
- default: {},
69
- });
32
+ }
70
33
 
71
34
  const styles = StyleSheet.create({
72
35
  overlay: {
73
36
  ...StyleSheet.absoluteFillObject,
74
37
  backgroundColor: 'rgba(0, 0, 0, 0.5)',
38
+ // Disable touch highlight on mobile Safari.
39
+ // WebkitTapHighlightColor must be used outside of StyleSheet.create because react-native-web will omit the property.
40
+ // @ts-expect-error: WebkitTapHighlightColor is web only
41
+ WebkitTapHighlightColor: 'transparent',
42
+ transition: 'opacity 0.3s',
75
43
  },
76
44
  pressable: {
77
45
  flex: 1,
78
- pointerEvents: 'auto',
79
46
  },
80
47
  });
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SWIPE_MIN_VELOCITY = exports.SWIPE_MIN_OFFSET = exports.SWIPE_MIN_DISTANCE = exports.SWIPE_EDGE_WIDTH = void 0;
7
- const SWIPE_EDGE_WIDTH = exports.SWIPE_EDGE_WIDTH = 32;
8
- const SWIPE_MIN_OFFSET = exports.SWIPE_MIN_OFFSET = 5;
9
- const SWIPE_MIN_DISTANCE = exports.SWIPE_MIN_DISTANCE = 60;
10
- const SWIPE_MIN_VELOCITY = exports.SWIPE_MIN_VELOCITY = 500;
11
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["SWIPE_EDGE_WIDTH","exports","SWIPE_MIN_OFFSET","SWIPE_MIN_DISTANCE","SWIPE_MIN_VELOCITY"],"sourceRoot":"../../src","sources":["constants.tsx"],"mappings":";;;;;;AAAO,MAAMA,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,EAAE;AAC3B,MAAME,gBAAgB,GAAAD,OAAA,CAAAC,gBAAA,GAAG,CAAC;AAC1B,MAAMC,kBAAkB,GAAAF,OAAA,CAAAE,kBAAA,GAAG,EAAE;AAC7B,MAAMC,kBAAkB,GAAAH,OAAA,CAAAG,kBAAA,GAAG,GAAG"}
@@ -1,5 +0,0 @@
1
- export const SWIPE_EDGE_WIDTH = 32;
2
- export const SWIPE_MIN_OFFSET = 5;
3
- export const SWIPE_MIN_DISTANCE = 60;
4
- export const SWIPE_MIN_VELOCITY = 500;
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["SWIPE_EDGE_WIDTH","SWIPE_MIN_OFFSET","SWIPE_MIN_DISTANCE","SWIPE_MIN_VELOCITY"],"sourceRoot":"../../src","sources":["constants.tsx"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,GAAG,EAAE;AAClC,OAAO,MAAMC,gBAAgB,GAAG,CAAC;AACjC,OAAO,MAAMC,kBAAkB,GAAG,EAAE;AACpC,OAAO,MAAMC,kBAAkB,GAAG,GAAG"}
@@ -1,5 +0,0 @@
1
- export declare const SWIPE_EDGE_WIDTH = 32;
2
- export declare const SWIPE_MIN_OFFSET = 5;
3
- export declare const SWIPE_MIN_DISTANCE = 60;
4
- export declare const SWIPE_MIN_VELOCITY = 500;
5
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.tsx"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC"}
package/src/constants.tsx DELETED
@@ -1,4 +0,0 @@
1
- export const SWIPE_EDGE_WIDTH = 32;
2
- export const SWIPE_MIN_OFFSET = 5;
3
- export const SWIPE_MIN_DISTANCE = 60;
4
- export const SWIPE_MIN_VELOCITY = 500;