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