mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 21:05:29 +08:00
chore: add deprecation warnings
This commit is contained in:
@@ -43,7 +43,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0",
|
||||
"color": "^3.1.3"
|
||||
"color": "^3.1.3",
|
||||
"warn-once": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^5.8.9",
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
DrawerActionHelpers,
|
||||
ParamListBase,
|
||||
} from '@react-navigation/native';
|
||||
|
||||
import warnOnce from 'warn-once';
|
||||
import DrawerView from '../views/DrawerView';
|
||||
import type {
|
||||
DrawerNavigationOptions,
|
||||
@@ -27,8 +27,46 @@ function DrawerNavigator({
|
||||
backBehavior,
|
||||
children,
|
||||
screenOptions,
|
||||
// @ts-expect-error: lazy is deprecated
|
||||
lazy,
|
||||
// @ts-expect-error: drawerContentOptions is deprecated
|
||||
drawerContentOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
let defaultScreenOptions: DrawerNavigationOptions = {};
|
||||
|
||||
if (drawerContentOptions) {
|
||||
Object.assign(defaultScreenOptions, {
|
||||
drawerPosition: drawerContentOptions.drawerPosition,
|
||||
drawerType: drawerContentOptions.drawerType,
|
||||
swipeEdgeWidth: drawerContentOptions.edgeWidth,
|
||||
drawerHideStatusBarOnOpen: drawerContentOptions.hideStatusBar,
|
||||
keyboardDismissMode: drawerContentOptions.keyboardDismissMode,
|
||||
swipeMinDistance: drawerContentOptions.minSwipeDistance,
|
||||
overlayColor: drawerContentOptions.overlayColor,
|
||||
drawerStatusBarAnimation: drawerContentOptions.statusBarAnimation,
|
||||
gestureHandlerProps: drawerContentOptions.gestureHandlerProps,
|
||||
});
|
||||
|
||||
warnOnce(
|
||||
drawerContentOptions,
|
||||
`Drawer Navigator: 'drawerContentOptions' is deprecated. Migrate the options to 'screenOptions' instead.\n\nPlace the following in 'screenOptions' in your code to keep current behavior:\n\n${JSON.stringify(
|
||||
defaultScreenOptions,
|
||||
null,
|
||||
2
|
||||
)}\n\nSee https://reactnavigation.org/docs/6.x/drawer-navigator#options for more details.`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof lazy === 'boolean') {
|
||||
defaultScreenOptions.lazy = lazy;
|
||||
|
||||
warnOnce(
|
||||
true,
|
||||
`Drawer Navigator: 'lazy' in props is deprecated. Move it to 'screenOptions' instead.`
|
||||
);
|
||||
}
|
||||
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
DrawerNavigationState<ParamListBase>,
|
||||
DrawerRouterOptions,
|
||||
@@ -41,6 +79,7 @@ function DrawerNavigator({
|
||||
backBehavior,
|
||||
children,
|
||||
screenOptions,
|
||||
defaultScreenOptions,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user