chore: add deprecation warnings

This commit is contained in:
Satyajit Sahoo
2021-03-09 17:27:40 +01:00
parent 22610014b3
commit 8e0ae5fc79
9 changed files with 152 additions and 5 deletions

View File

@@ -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",

View File

@@ -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 (