Skip to content

Commit d40c7a8

Browse files
committed
fix: React Navigation Typescript typing fix
1 parent 353115b commit d40c7a8

File tree

3 files changed

+220
-19
lines changed

3 files changed

+220
-19
lines changed

lib/NavigationService.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import * as React from "react";
2-
import { StackActions } from "@react-navigation/native";
2+
import { NavigationContainerRef, StackActions } from "@react-navigation/native";
33

4-
export const isReadyRef = React.createRef();
5-
export const navigationRef = React.createRef();
4+
export let isReadyRef = React.createRef<any>();
5+
export let navigationRef = React.createRef<NavigationContainerRef>();
66

77
export const navigate = (routeName: string, params?: any) => {
88
if (isReadyRef.current && navigationRef && navigationRef.current) {
99
// Perform navigation if the app has mounted
10-
navigationRef?.current.navigate(routeName, params);
10+
navigationRef?.current?.navigate(routeName, params);
1111
}
1212
};
1313

14-
export const push = (routeName: string, params?: any, ...args: any) => {
14+
export const push = (routeName: string, params?: any) => {
1515
if (isReadyRef.current && navigationRef && navigationRef.current) {
1616
// Perform navigation if the app has mounted
17-
navigationRef.current.dispatch(
18-
StackActions.push(routeName, params, ...args),
19-
);
17+
navigationRef.current.dispatch(StackActions.push(routeName, params));
2018
}
2119
};
2220

23-
export const goBack = (...args: any) => {
21+
export const goBack = () => {
2422
if (isReadyRef.current && navigationRef && navigationRef.current) {
2523
// Perform navigation if the app has mounted
26-
navigationRef.current.goBack(...args);
24+
navigationRef.current.goBack();
2725
}
2826
};
2927

@@ -34,10 +32,10 @@ export const pop = (...args: any) => {
3432
}
3533
};
3634

37-
export const popToTop = (...args: any) => {
35+
export const popToTop = () => {
3836
if (isReadyRef.current && navigationRef && navigationRef.current) {
3937
// Perform navigation if the app has mounted
40-
navigationRef.current?.dispatch(StackActions.popToTop(...args));
38+
navigationRef.current?.dispatch(StackActions.popToTop());
4139
}
4240
};
4341

package-lock.json

Lines changed: 206 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "react-navigation-helpers",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Easy to use React Navigation with these helpers for React Navigation on React Native",
55
"keywords": [
66
"v5",
77
"helpers",
8+
"react-navigation-helpers",
9+
"@react-navigation-helpers",
10+
"@react-navigation",
811
"react-navigation",
912
"navigation",
1013
"FreakyCoder",

0 commit comments

Comments
 (0)