@react-navigation/drawer 7.0.0-alpha.1 → 7.0.0-alpha.10
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 +8 -5
- 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 +8 -5
- 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 +3 -3
- 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 +12 -23
- 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 +5 -1
- 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 +6 -2
- 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 +2 -2
- 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 +13 -24
- 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 -4
- 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 -2
- 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 -2
- package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerView.d.ts +3 -3
- 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 +24 -25
- package/src/navigators/createDrawerNavigator.tsx +9 -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 +7 -9
- package/src/views/DrawerItem.tsx +9 -76
- package/src/views/DrawerItemList.tsx +6 -6
- package/src/views/DrawerToggleButton.tsx +2 -4
- package/src/views/DrawerView.tsx +22 -30
- package/src/views/ScreenFallback.tsx +6 -1
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { useLocale } from '@react-navigation/native';
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
I18nManager,
|
|
4
|
-
ScrollView,
|
|
5
|
-
ScrollViewProps,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
} from 'react-native';
|
|
3
|
+
import { ScrollView, type ScrollViewProps, StyleSheet } from 'react-native';
|
|
8
4
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
9
5
|
|
|
10
6
|
import { DrawerPositionContext } from '../utils/DrawerPositionContext';
|
|
@@ -19,10 +15,12 @@ function DrawerContentScrollViewInner(
|
|
|
19
15
|
) {
|
|
20
16
|
const drawerPosition = React.useContext(DrawerPositionContext);
|
|
21
17
|
const insets = useSafeAreaInsets();
|
|
18
|
+
const { direction } = useLocale();
|
|
22
19
|
|
|
23
|
-
const isRight =
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const isRight =
|
|
21
|
+
direction === 'rtl'
|
|
22
|
+
? drawerPosition === 'left'
|
|
23
|
+
: drawerPosition === 'right';
|
|
26
24
|
|
|
27
25
|
return (
|
|
28
26
|
<ScrollView
|
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,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonActions,
|
|
3
3
|
DrawerActions,
|
|
4
|
-
DrawerNavigationState,
|
|
5
|
-
ParamListBase,
|
|
6
|
-
|
|
4
|
+
type DrawerNavigationState,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
useLinkBuilder,
|
|
7
7
|
} from '@react-navigation/native';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ type Props = {
|
|
|
20
20
|
* Component that renders the navigation list in the drawer.
|
|
21
21
|
*/
|
|
22
22
|
export function DrawerItemList({ state, navigation, descriptors }: Props) {
|
|
23
|
-
const { buildHref } =
|
|
23
|
+
const { buildHref } = useLinkBuilder();
|
|
24
24
|
|
|
25
25
|
const focusedRoute = state.routes[state.index];
|
|
26
26
|
const focusedDescriptor = descriptors[focusedRoute.key];
|
|
@@ -71,8 +71,8 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
|
|
|
71
71
|
drawerLabel !== undefined
|
|
72
72
|
? drawerLabel
|
|
73
73
|
: title !== undefined
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
? title
|
|
75
|
+
: route.name
|
|
76
76
|
}
|
|
77
77
|
icon={drawerIcon}
|
|
78
78
|
focused={focused}
|
|
@@ -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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getDefaultSidebarWidth,
|
|
2
3
|
getHeaderTitle,
|
|
3
4
|
Header,
|
|
4
5
|
SafeAreaProviderCompat,
|
|
@@ -6,13 +7,14 @@ import {
|
|
|
6
7
|
} from '@react-navigation/elements';
|
|
7
8
|
import {
|
|
8
9
|
DrawerActions,
|
|
9
|
-
DrawerNavigationState,
|
|
10
|
-
DrawerStatus,
|
|
11
|
-
ParamListBase,
|
|
10
|
+
type DrawerNavigationState,
|
|
11
|
+
type DrawerStatus,
|
|
12
|
+
type ParamListBase,
|
|
13
|
+
useLocale,
|
|
12
14
|
useTheme,
|
|
13
15
|
} from '@react-navigation/native';
|
|
14
16
|
import * as React from 'react';
|
|
15
|
-
import {
|
|
17
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
16
18
|
import { Drawer } from 'react-native-drawer-layout';
|
|
17
19
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
18
20
|
import useLatestCallback from 'use-latest-callback';
|
|
@@ -25,6 +27,7 @@ import type {
|
|
|
25
27
|
DrawerNavigationHelpers,
|
|
26
28
|
DrawerNavigationProp,
|
|
27
29
|
} from '../types';
|
|
30
|
+
import { addCancelListener } from '../utils/addCancelListener';
|
|
28
31
|
import { DrawerPositionContext } from '../utils/DrawerPositionContext';
|
|
29
32
|
import { DrawerStatusContext } from '../utils/DrawerStatusContext';
|
|
30
33
|
import { getDrawerStatusFromState } from '../utils/getDrawerStatusFromState';
|
|
@@ -51,10 +54,12 @@ function DrawerViewBase({
|
|
|
51
54
|
Platform.OS === 'android' ||
|
|
52
55
|
Platform.OS === 'ios',
|
|
53
56
|
}: Props) {
|
|
57
|
+
const { direction } = useLocale();
|
|
58
|
+
|
|
54
59
|
const focusedRouteKey = state.routes[state.index].key;
|
|
55
60
|
const {
|
|
56
61
|
drawerHideStatusBarOnOpen,
|
|
57
|
-
drawerPosition =
|
|
62
|
+
drawerPosition = direction === 'rtl' ? 'right' : 'left',
|
|
58
63
|
drawerStatusBarAnimation,
|
|
59
64
|
drawerStyle,
|
|
60
65
|
drawerType,
|
|
@@ -153,31 +158,10 @@ function DrawerViewBase({
|
|
|
153
158
|
return true;
|
|
154
159
|
};
|
|
155
160
|
|
|
156
|
-
const handleEscape = (e: KeyboardEvent) => {
|
|
157
|
-
if (e.key === 'Escape') {
|
|
158
|
-
handleHardwareBack();
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
161
|
// We only add the listeners when drawer opens
|
|
163
162
|
// This way we can make sure that the listener is added as late as possible
|
|
164
163
|
// This will make sure that our handler will run first when back button is pressed
|
|
165
|
-
|
|
166
|
-
'hardwareBackPress',
|
|
167
|
-
handleHardwareBack
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
if (Platform.OS === 'web') {
|
|
171
|
-
document?.body?.addEventListener?.('keyup', handleEscape);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return () => {
|
|
175
|
-
subscription.remove();
|
|
176
|
-
|
|
177
|
-
if (Platform.OS === 'web') {
|
|
178
|
-
document?.body?.removeEventListener?.('keyup', handleEscape);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
164
|
+
return addCancelListener(handleHardwareBack);
|
|
181
165
|
}, [
|
|
182
166
|
defaultStatus,
|
|
183
167
|
drawerStatus,
|
|
@@ -215,8 +199,13 @@ function DrawerViewBase({
|
|
|
215
199
|
return null;
|
|
216
200
|
}
|
|
217
201
|
|
|
218
|
-
if (
|
|
219
|
-
|
|
202
|
+
if (
|
|
203
|
+
lazy &&
|
|
204
|
+
!loaded.includes(route.key) &&
|
|
205
|
+
!isFocused &&
|
|
206
|
+
!state.preloadedRouteKeys.includes(route.key)
|
|
207
|
+
) {
|
|
208
|
+
// Don't render a lazy screen if we've never navigated to it or it wasn't preloaded
|
|
220
209
|
return null;
|
|
221
210
|
}
|
|
222
211
|
|
|
@@ -295,7 +284,10 @@ function DrawerViewBase({
|
|
|
295
284
|
overlayAccessibilityLabel={overlayAccessibilityLabel}
|
|
296
285
|
drawerPosition={drawerPosition}
|
|
297
286
|
drawerStyle={[
|
|
298
|
-
{
|
|
287
|
+
{
|
|
288
|
+
backgroundColor: colors.card,
|
|
289
|
+
width: getDefaultSidebarWidth(dimensions),
|
|
290
|
+
},
|
|
299
291
|
drawerType === 'permanent' &&
|
|
300
292
|
(drawerPosition === 'left'
|
|
301
293
|
? {
|
|
@@ -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;
|