mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-30 05:15:25 +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 (
|
||||
|
||||
Reference in New Issue
Block a user