Skip to content

Commit 5985442

Browse files
committed
fix: Fixed deprecation warnings
1 parent 8d8da00 commit 5985442

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/helpers/navigationToActionObject.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { StackActions } from '@react-navigation/native';
1111
* Convert a react-navigation's navigation prop to NavigationActionsObject
1212
* @param navigation
1313
*/
14-
export const navigationToActionObject = (navigation: any, state: any): NavigationActionsObject => {
14+
export const navigationToActionObject = (navigation: any, inputRoute: any): NavigationActionsObject => {
1515
const { navigate, goBack, setParams, dispatch } = navigation as any;
1616

1717
const push = (routeName: string, params: any) => {
@@ -29,7 +29,21 @@ export const navigationToActionObject = (navigation: any, state: any): Navigatio
2929
dispatch(pushAction);
3030
};
3131

32-
const otherParams: any = { ...state.params };
32+
// //////////////////////////////
33+
// Experimental:
34+
// Removing state property because of the following warning:
35+
//
36+
// eslint-disable-next-line max-len
37+
// Accessing the 'state' property of the 'route' object is not supported. If you want to get the focused route name, use the 'getFocusedRouteNameFromRoute' helper instead: https://reactnavigation.org/docs/5.x/screen-options-resolution/#setting-parent-screen-options-based-on-child-navigators-state
38+
//
39+
const route = {
40+
key: inputRoute.key,
41+
name: inputRoute.name,
42+
params: inputRoute.params,
43+
};
44+
// //////////////////////////////
45+
46+
const otherParams: any = { ...route.params };
3347

3448
// Extract internal variables
3549
const url = otherParams.__path_url__ ? `/${otherParams.__path_url__}` : undefined;
@@ -39,6 +53,7 @@ export const navigationToActionObject = (navigation: any, state: any): Navigatio
3953
delete otherParams.__path_url__;
4054
delete otherParams.__path_search__;
4155

56+
4257
const actions: NavigationActionsObject = {
4358
goBack: () => goBack(),
4459
pop,
@@ -56,7 +71,7 @@ export const navigationToActionObject = (navigation: any, state: any): Navigatio
5671
setParams,
5772

5873
getParam: (paramName: any, defaultValue: any): any => {
59-
const params = state.params;
74+
const params = route.params;
6075

6176
if (params && paramName in params) {
6277
return params[paramName];
@@ -66,10 +81,10 @@ export const navigationToActionObject = (navigation: any, state: any): Navigatio
6681
},
6782

6883
state: {
69-
...state,
70-
routeName: state.name,
84+
...route,
85+
routeName: route.name,
7186
search: search,
72-
url: (state as any).path || url,
87+
url: (route as any).path || url,
7388
},
7489

7590
source: navigation,

src/helpers/resolveRouteOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const resolveRouteOptions = (route: RouteConfig, navigationData: Navigati
1616
}
1717

1818
if (route.navigationOptions) {
19-
console.warn('route.navigationOptions is deprecated');
19+
// eslint-disable-next-line max-len
20+
console.warn(`route.navigationOptions is deprecated. Refactor ${route.name} route to use route.options instead.`);
2021
}
2122

2223
const options = resolveThunk(

0 commit comments

Comments
 (0)