mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-20 04:21:11 +08:00
chore: add deprecation warnings
This commit is contained in:
@@ -38,7 +38,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",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import warnOnce from 'warn-once';
|
||||
import {
|
||||
useNavigationBuilder,
|
||||
createNavigatorFactory,
|
||||
@@ -26,8 +27,49 @@ function BottomTabNavigator({
|
||||
children,
|
||||
screenOptions,
|
||||
sceneContainerStyle,
|
||||
// @ts-expect-error: lazy is deprecated
|
||||
lazy,
|
||||
// @ts-expect-error: tabBarOptions is deprecated
|
||||
tabBarOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
let defaultScreenOptions: BottomTabNavigationOptions = {};
|
||||
|
||||
if (tabBarOptions) {
|
||||
Object.assign(defaultScreenOptions, {
|
||||
tabBarHideOnKeyboard: tabBarOptions.keyboardHidesTabBar,
|
||||
tabBarActiveTintColor: tabBarOptions.activeTintColor,
|
||||
tabBarInactiveTintColor: tabBarOptions.inactiveTintColor,
|
||||
tabBarActiveBackgroundColor: tabBarOptions.activeBackgroundColor,
|
||||
tabBarInactiveBackgroundColor: tabBarOptions.inactiveBackgroundColor,
|
||||
tabBarAllowFontScaling: tabBarOptions.allowFontScaling,
|
||||
tabBarShowLabel: tabBarOptions.showLabel,
|
||||
tabBarLabelStyle: tabBarOptions.labelStyle,
|
||||
tabBarIconStyle: tabBarOptions.iconStyle,
|
||||
tabBarItemStyle: tabBarOptions.tabStyle,
|
||||
tabBarLabelPosition: tabBarOptions.labelPosition,
|
||||
tabBarAdaptive: tabBarOptions.adaptive,
|
||||
});
|
||||
|
||||
warnOnce(
|
||||
tabBarOptions,
|
||||
`Bottom Tab Navigator: 'tabBarOptions' 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/bottom-tab-navigator#options for more details.`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof lazy === 'boolean') {
|
||||
defaultScreenOptions.lazy = lazy;
|
||||
|
||||
warnOnce(
|
||||
true,
|
||||
`Bottom Tab Navigator: 'lazy' in props is deprecated. Move it to 'screenOptions' instead.`
|
||||
);
|
||||
}
|
||||
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
TabNavigationState<ParamListBase>,
|
||||
TabRouterOptions,
|
||||
@@ -39,6 +81,7 @@ function BottomTabNavigator({
|
||||
backBehavior,
|
||||
children,
|
||||
screenOptions,
|
||||
defaultScreenOptions,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"color": "^3.1.3"
|
||||
"color": "^3.1.3",
|
||||
"warn-once": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^5.8.9",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import warnOnce from 'warn-once';
|
||||
import {
|
||||
useNavigationBuilder,
|
||||
createNavigatorFactory,
|
||||
@@ -25,8 +26,53 @@ function MaterialTopTabNavigator({
|
||||
backBehavior,
|
||||
children,
|
||||
screenOptions,
|
||||
// @ts-expect-error: lazy is deprecated
|
||||
lazy,
|
||||
// @ts-expect-error: tabBarOptions is deprecated
|
||||
tabBarOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
let defaultScreenOptions: MaterialTopTabNavigationOptions = {};
|
||||
|
||||
if (tabBarOptions) {
|
||||
Object.assign(defaultScreenOptions, {
|
||||
tabBarActiveTintColor: tabBarOptions.activeTintColor,
|
||||
tabBarInactiveTintColor: tabBarOptions.inactiveTintColor,
|
||||
tabBarPressColor: tabBarOptions.pressColor,
|
||||
tabBarPressOpacity: tabBarOptions.pressOpacity,
|
||||
tabBarShowLabel: tabBarOptions.showLabel,
|
||||
tabBarShowIcon: tabBarOptions.showIcon,
|
||||
tabBarAllowFontScaling: tabBarOptions.allowFontScaling,
|
||||
tabBarBounces: tabBarOptions.bounces,
|
||||
tabBarScrollEnabled: tabBarOptions.scrollEnabled,
|
||||
tabBarIconStyle: tabBarOptions.iconStyle,
|
||||
tabBarLabelStyle: tabBarOptions.labelStyle,
|
||||
tabBarItemStyle: tabBarOptions.tabStyle,
|
||||
tabBarIndicatorStyle: tabBarOptions.indicatorStyle,
|
||||
tabBarIndicatorContainerStyle: tabBarOptions.indicatorContainerStyle,
|
||||
tabBarContentContainerStyle: tabBarOptions.contentContainerStyle,
|
||||
tabBarStyle: tabBarOptions.style,
|
||||
});
|
||||
|
||||
warnOnce(
|
||||
tabBarOptions,
|
||||
`Material Top Tab Navigator: 'tabBarOptions' 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/material-top-tab-navigator#options for more details.`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof lazy === 'boolean') {
|
||||
defaultScreenOptions.lazy = lazy;
|
||||
|
||||
warnOnce(
|
||||
true,
|
||||
`Material Top Tab Navigator: 'lazy' in props is deprecated. Move it to 'screenOptions' instead.`
|
||||
);
|
||||
}
|
||||
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
TabNavigationState<ParamListBase>,
|
||||
TabRouterOptions,
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0",
|
||||
"color": "^3.1.3",
|
||||
"react-native-iphone-x-helper": "^1.3.0"
|
||||
"react-native-iphone-x-helper": "^1.3.0",
|
||||
"warn-once": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^5.8.9",
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
ParamListBase,
|
||||
StackActionHelpers,
|
||||
} from '@react-navigation/native';
|
||||
import warnOnce from 'warn-once';
|
||||
import StackView from '../views/Stack/StackView';
|
||||
import type {
|
||||
StackNavigationConfig,
|
||||
@@ -29,6 +30,14 @@ function StackNavigator({
|
||||
screenOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
// @ts-expect-error: headerMode='none' is deprecated
|
||||
const isHeaderModeNone = rest.headerMode === 'none';
|
||||
|
||||
warnOnce(
|
||||
isHeaderModeNone,
|
||||
`Stack Navigator: 'headerMode="none"' is deprecated. Use 'headerShown: false' in 'screenOptions' instead.`
|
||||
);
|
||||
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
StackNavigationState<ParamListBase>,
|
||||
StackRouterOptions,
|
||||
@@ -40,6 +49,7 @@ function StackNavigator({
|
||||
children,
|
||||
screenOptions,
|
||||
defaultScreenOptions: {
|
||||
headerShown: !isHeaderModeNone,
|
||||
gestureEnabled: Platform.OS === 'ios',
|
||||
animationEnabled:
|
||||
Platform.OS !== 'web' &&
|
||||
|
||||
@@ -19256,6 +19256,11 @@ walker@^1.0.7, walker@~1.0.5:
|
||||
dependencies:
|
||||
makeerror "1.0.x"
|
||||
|
||||
warn-once@^0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.0.1.tgz#71eda54c88f240c4461e5c7a84cac2263caf3a4e"
|
||||
integrity sha512-Sh/kR0dQ9Tlr70E2zuR8mZ0yxmN9kGMNfvlwWWRi7frSox2uRC7U659Le8jBIqvjykSbvo9JX9ttsqw4vZPLmA==
|
||||
|
||||
watchpack-chokidar2@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/watchpack-chokidar2/-/watchpack-chokidar2-2.0.1.tgz#38500072ee6ece66f3769936950ea1771be1c957"
|
||||
|
||||
Reference in New Issue
Block a user