@react-navigation/drawer 7.0.0-alpha.4 → 7.0.0-alpha.6
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.map +1 -1
- package/lib/commonjs/navigators/createDrawerNavigator.js +5 -4
- package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/DrawerPositionContext.js +3 -4
- package/lib/commonjs/utils/DrawerPositionContext.js.map +1 -1
- package/lib/commonjs/utils/DrawerStatusContext.js +3 -4
- package/lib/commonjs/utils/DrawerStatusContext.js.map +1 -1
- package/lib/commonjs/utils/addCancelListener.js +19 -0
- package/lib/commonjs/utils/addCancelListener.js.map +1 -0
- package/lib/commonjs/utils/addCancelListener.native.js +15 -0
- package/lib/commonjs/utils/addCancelListener.native.js.map +1 -0
- package/lib/commonjs/utils/getDrawerStatusFromState.js +1 -1
- package/lib/commonjs/utils/getDrawerStatusFromState.js.map +1 -1
- package/lib/commonjs/utils/useDrawerStatus.js +2 -2
- package/lib/commonjs/utils/useDrawerStatus.js.map +1 -1
- package/lib/commonjs/views/DrawerContent.js +2 -2
- package/lib/commonjs/views/DrawerContent.js.map +1 -1
- package/lib/commonjs/views/DrawerContentScrollView.js +3 -4
- package/lib/commonjs/views/DrawerContentScrollView.js.map +1 -1
- package/lib/commonjs/views/DrawerItem.js +9 -59
- package/lib/commonjs/views/DrawerItem.js.map +1 -1
- package/lib/commonjs/views/DrawerItemList.js +2 -2
- package/lib/commonjs/views/DrawerItemList.js.map +1 -1
- package/lib/commonjs/views/DrawerToggleButton.js +4 -6
- package/lib/commonjs/views/DrawerToggleButton.js.map +1 -1
- package/lib/commonjs/views/DrawerView.js +4 -20
- package/lib/commonjs/views/DrawerView.js.map +1 -1
- package/lib/commonjs/views/ScreenFallback.js +4 -6
- package/lib/commonjs/views/ScreenFallback.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createDrawerNavigator.js +2 -0
- package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/DrawerPositionContext.js.map +1 -1
- package/lib/module/utils/DrawerStatusContext.js.map +1 -1
- package/lib/module/utils/addCancelListener.js +12 -0
- package/lib/module/utils/addCancelListener.js.map +1 -0
- package/lib/module/utils/addCancelListener.native.js +8 -0
- package/lib/module/utils/addCancelListener.native.js.map +1 -0
- package/lib/module/utils/getDrawerStatusFromState.js +1 -1
- package/lib/module/utils/getDrawerStatusFromState.js.map +1 -1
- package/lib/module/utils/useDrawerStatus.js.map +1 -1
- package/lib/module/views/DrawerContent.js.map +1 -1
- package/lib/module/views/DrawerContentScrollView.js.map +1 -1
- package/lib/module/views/DrawerItem.js +9 -59
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js.map +1 -1
- package/lib/module/views/DrawerToggleButton.js +2 -4
- package/lib/module/views/DrawerToggleButton.js.map +1 -1
- package/lib/module/views/DrawerView.js +3 -19
- package/lib/module/views/DrawerView.js.map +1 -1
- package/lib/module/views/ScreenFallback.js +2 -4
- package/lib/module/views/ScreenFallback.js.map +1 -1
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +4 -3
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -10
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/addCancelListener.d.ts +2 -0
- package/lib/typescript/src/utils/addCancelListener.d.ts.map +1 -0
- package/lib/typescript/src/utils/addCancelListener.native.d.ts +2 -0
- package/lib/typescript/src/utils/addCancelListener.native.d.ts.map +1 -0
- package/lib/typescript/src/views/DrawerContent.d.ts +2 -1
- package/lib/typescript/src/views/DrawerContent.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerContentScrollView.d.ts +1 -1
- package/lib/typescript/src/views/DrawerContentScrollView.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerItem.d.ts +3 -3
- package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerItemList.d.ts +1 -1
- package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerToggleButton.d.ts +2 -1
- package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerView.d.ts +3 -2
- package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
- package/lib/typescript/src/views/ScreenFallback.d.ts +3 -3
- package/lib/typescript/src/views/ScreenFallback.d.ts.map +1 -1
- package/package.json +21 -22
- package/src/navigators/createDrawerNavigator.tsx +7 -5
- package/src/types.tsx +2 -12
- package/src/utils/addCancelListener.native.tsx +12 -0
- package/src/utils/addCancelListener.tsx +13 -0
- package/src/views/DrawerContentScrollView.tsx +1 -1
- package/src/views/DrawerItem.tsx +9 -76
- package/src/views/DrawerItemList.tsx +2 -2
- package/src/views/DrawerToggleButton.tsx +2 -4
- package/src/views/DrawerView.tsx +6 -25
- package/src/views/ScreenFallback.tsx +6 -1
package/src/views/DrawerItem.tsx
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { PlatformPressable } from '@react-navigation/elements';
|
|
2
|
-
import {
|
|
1
|
+
import { PlatformPressable, Text } from '@react-navigation/elements';
|
|
2
|
+
import { type Route, useTheme } from '@react-navigation/native';
|
|
3
3
|
import Color from 'color';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
StyleProp,
|
|
6
|
+
type StyleProp,
|
|
8
7
|
StyleSheet,
|
|
9
|
-
|
|
10
|
-
TextStyle,
|
|
8
|
+
type TextStyle,
|
|
11
9
|
View,
|
|
12
|
-
ViewStyle,
|
|
10
|
+
type ViewStyle,
|
|
13
11
|
} from 'react-native';
|
|
14
12
|
|
|
15
13
|
type Props = {
|
|
@@ -96,65 +94,6 @@ type Props = {
|
|
|
96
94
|
testID?: string;
|
|
97
95
|
};
|
|
98
96
|
|
|
99
|
-
const LinkPressable = ({
|
|
100
|
-
route,
|
|
101
|
-
href,
|
|
102
|
-
children,
|
|
103
|
-
style,
|
|
104
|
-
onPress,
|
|
105
|
-
onLongPress,
|
|
106
|
-
onPressIn,
|
|
107
|
-
onPressOut,
|
|
108
|
-
accessibilityRole,
|
|
109
|
-
...rest
|
|
110
|
-
}: Omit<React.ComponentProps<typeof PlatformPressable>, 'style'> & {
|
|
111
|
-
style: StyleProp<ViewStyle>;
|
|
112
|
-
} & {
|
|
113
|
-
route: Route<string>;
|
|
114
|
-
href?: string;
|
|
115
|
-
children: React.ReactNode;
|
|
116
|
-
onPress?: () => void;
|
|
117
|
-
}) => {
|
|
118
|
-
if (Platform.OS === 'web') {
|
|
119
|
-
// React Native Web doesn't forward `onClick` if we use `TouchableWithoutFeedback`.
|
|
120
|
-
// We need to use `onClick` to be able to prevent default browser handling of links.
|
|
121
|
-
return (
|
|
122
|
-
<Link
|
|
123
|
-
{...rest}
|
|
124
|
-
href={href}
|
|
125
|
-
action={CommonActions.navigate(route.name, route.params)}
|
|
126
|
-
style={[styles.button, style]}
|
|
127
|
-
onPress={(e: any) => {
|
|
128
|
-
if (
|
|
129
|
-
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
|
130
|
-
(e.button == null || e.button === 0) // ignore everything but left clicks
|
|
131
|
-
) {
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
onPress?.(e);
|
|
134
|
-
}
|
|
135
|
-
}}
|
|
136
|
-
// types for PressableProps and TextProps are incompatible with each other by `null` so we
|
|
137
|
-
// can't use {...rest} for these 3 props
|
|
138
|
-
onLongPress={onLongPress ?? undefined}
|
|
139
|
-
onPressIn={onPressIn ?? undefined}
|
|
140
|
-
onPressOut={onPressOut ?? undefined}
|
|
141
|
-
>
|
|
142
|
-
{children}
|
|
143
|
-
</Link>
|
|
144
|
-
);
|
|
145
|
-
} else {
|
|
146
|
-
return (
|
|
147
|
-
<PlatformPressable
|
|
148
|
-
{...rest}
|
|
149
|
-
accessibilityRole={accessibilityRole}
|
|
150
|
-
onPress={onPress}
|
|
151
|
-
>
|
|
152
|
-
<View style={style}>{children}</View>
|
|
153
|
-
</PlatformPressable>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
97
|
/**
|
|
159
98
|
* A component used to show an action item with an icon and a label in a navigation drawer.
|
|
160
99
|
*/
|
|
@@ -162,7 +101,6 @@ export function DrawerItem(props: Props) {
|
|
|
162
101
|
const { colors, fonts } = useTheme();
|
|
163
102
|
|
|
164
103
|
const {
|
|
165
|
-
route,
|
|
166
104
|
href,
|
|
167
105
|
icon,
|
|
168
106
|
label,
|
|
@@ -196,19 +134,17 @@ export function DrawerItem(props: Props) {
|
|
|
196
134
|
{...rest}
|
|
197
135
|
style={[styles.container, { borderRadius, backgroundColor }, style]}
|
|
198
136
|
>
|
|
199
|
-
<
|
|
137
|
+
<PlatformPressable
|
|
200
138
|
testID={testID}
|
|
201
139
|
onPress={onPress}
|
|
202
|
-
style={[styles.wrapper, { borderRadius }]}
|
|
203
140
|
accessibilityLabel={accessibilityLabel}
|
|
204
141
|
accessibilityRole="button"
|
|
205
142
|
accessibilityState={{ selected: focused }}
|
|
206
143
|
pressColor={pressColor}
|
|
207
144
|
pressOpacity={pressOpacity}
|
|
208
|
-
route={route}
|
|
209
145
|
href={href}
|
|
210
146
|
>
|
|
211
|
-
<
|
|
147
|
+
<View style={[styles.wrapper, { borderRadius }]}>
|
|
212
148
|
{iconNode}
|
|
213
149
|
<View
|
|
214
150
|
style={[
|
|
@@ -228,8 +164,8 @@ export function DrawerItem(props: Props) {
|
|
|
228
164
|
label({ color, focused })
|
|
229
165
|
)}
|
|
230
166
|
</View>
|
|
231
|
-
</
|
|
232
|
-
</
|
|
167
|
+
</View>
|
|
168
|
+
</PlatformPressable>
|
|
233
169
|
</View>
|
|
234
170
|
);
|
|
235
171
|
}
|
|
@@ -249,7 +185,4 @@ const styles = StyleSheet.create({
|
|
|
249
185
|
marginRight: 32,
|
|
250
186
|
flex: 1,
|
|
251
187
|
},
|
|
252
|
-
button: {
|
|
253
|
-
display: 'flex',
|
|
254
|
-
},
|
|
255
188
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements';
|
|
2
2
|
import {
|
|
3
3
|
DrawerActions,
|
|
4
|
-
ParamListBase,
|
|
4
|
+
type ParamListBase,
|
|
5
5
|
useNavigation,
|
|
6
6
|
} from '@react-navigation/native';
|
|
7
7
|
import * as React from 'react';
|
|
@@ -22,8 +22,6 @@ export function DrawerToggleButton({ tintColor, ...rest }: Props) {
|
|
|
22
22
|
return (
|
|
23
23
|
<PlatformPressable
|
|
24
24
|
{...rest}
|
|
25
|
-
accessible
|
|
26
|
-
accessibilityRole="button"
|
|
27
25
|
android_ripple={{ borderless: true }}
|
|
28
26
|
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
|
|
29
27
|
style={styles.touchable}
|
|
@@ -34,6 +32,7 @@ export function DrawerToggleButton({ tintColor, ...rest }: Props) {
|
|
|
34
32
|
>
|
|
35
33
|
<Image
|
|
36
34
|
style={[styles.icon, tintColor ? { tintColor } : null]}
|
|
35
|
+
resizeMode="contain"
|
|
37
36
|
source={require('./assets/toggle-drawer-icon.png')}
|
|
38
37
|
fadeDuration={0}
|
|
39
38
|
/>
|
|
@@ -46,7 +45,6 @@ const styles = StyleSheet.create({
|
|
|
46
45
|
height: 24,
|
|
47
46
|
width: 24,
|
|
48
47
|
margin: 3,
|
|
49
|
-
resizeMode: 'contain',
|
|
50
48
|
},
|
|
51
49
|
touchable: {
|
|
52
50
|
marginHorizontal: 11,
|
package/src/views/DrawerView.tsx
CHANGED
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
} from '@react-navigation/elements';
|
|
8
8
|
import {
|
|
9
9
|
DrawerActions,
|
|
10
|
-
DrawerNavigationState,
|
|
11
|
-
DrawerStatus,
|
|
12
|
-
ParamListBase,
|
|
10
|
+
type DrawerNavigationState,
|
|
11
|
+
type DrawerStatus,
|
|
12
|
+
type ParamListBase,
|
|
13
13
|
useLocale,
|
|
14
14
|
useTheme,
|
|
15
15
|
} from '@react-navigation/native';
|
|
16
16
|
import * as React from 'react';
|
|
17
|
-
import {
|
|
17
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
18
18
|
import { Drawer } from 'react-native-drawer-layout';
|
|
19
19
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
20
20
|
import useLatestCallback from 'use-latest-callback';
|
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
DrawerNavigationHelpers,
|
|
28
28
|
DrawerNavigationProp,
|
|
29
29
|
} from '../types';
|
|
30
|
+
import { addCancelListener } from '../utils/addCancelListener';
|
|
30
31
|
import { DrawerPositionContext } from '../utils/DrawerPositionContext';
|
|
31
32
|
import { DrawerStatusContext } from '../utils/DrawerStatusContext';
|
|
32
33
|
import { getDrawerStatusFromState } from '../utils/getDrawerStatusFromState';
|
|
@@ -157,30 +158,10 @@ function DrawerViewBase({
|
|
|
157
158
|
return true;
|
|
158
159
|
};
|
|
159
160
|
|
|
160
|
-
const handleEscape = (e: KeyboardEvent) => {
|
|
161
|
-
if (e.key === 'Escape') {
|
|
162
|
-
handleHardwareBack();
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
if (Platform.OS === 'web') {
|
|
167
|
-
document?.body?.addEventListener?.('keyup', handleEscape);
|
|
168
|
-
return () => {
|
|
169
|
-
document?.body?.removeEventListener?.('keyup', handleEscape);
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
161
|
// We only add the listeners when drawer opens
|
|
174
162
|
// This way we can make sure that the listener is added as late as possible
|
|
175
163
|
// This will make sure that our handler will run first when back button is pressed
|
|
176
|
-
|
|
177
|
-
'hardwareBackPress',
|
|
178
|
-
handleHardwareBack
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
return () => {
|
|
182
|
-
subscription?.remove?.();
|
|
183
|
-
};
|
|
164
|
+
return addCancelListener(handleHardwareBack);
|
|
184
165
|
}, [
|
|
185
166
|
defaultStatus,
|
|
186
167
|
drawerStatus,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ResourceSavingView } from '@react-navigation/elements';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type StyleProp,
|
|
5
|
+
View,
|
|
6
|
+
type ViewProps,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
4
9
|
|
|
5
10
|
type Props = {
|
|
6
11
|
visible: boolean;
|