Per the react-navigation docs, there is a 'replace' function available for stack navigators, but this doesn't seem to be supported in the react-native-screens stack-navigator.
https://reactnavigation.org/docs/navigation-prop/#navigator-dependent-functions
It should be available in native-stack. Can you provide an example where it does not work?
I am closing it since I think this issue is invalid. Feel free to comment if I am wrong.
@WoLewicki I think this issue meant that right now, to replace a screen we have to do
navigation.dispatch(
StackActions.replace('my screen', screenParams)
)
And it would be nice to be able to do
navigation.replace('my screen', )
Correct me if Im wrong though. Im using the following types:
NativeStackNavigationProp<Params, 'my screen'>
Oh I can see what is the problem now. Can you check if #695 fixes this?
Yep, I think #695 should fix this
export declare type NativeStackNavigationProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = string> = NavigationProp<ParamList, RouteName, StackNavigationState<ParamList>, NativeStackNavigationOptions, NativeStackNavigationEventMap> & {
/**
* Push a new screen onto the stack.
*
* @param name Name of the route for the tab.
* @param [params] Params object for the route.
*/
push<RouteName extends keyof ParamList>(...args: ParamList[RouteName] extends undefined | unknown ? [RouteName] | [RouteName, ParamList[RouteName]] : [RouteName, ParamList[RouteName]]): void;
/**
* Replace the current screen onto the stack.
*
* @param name Name of the route for the tab.
* @param [params] Params object for the route.
*/
replace<RouteName extends keyof ParamList>(...args: ParamList[RouteName] extends undefined | unknown ? [RouteName] | [RouteName, ParamList[RouteName]] : [RouteName, ParamList[RouteName]]): void;
/**
* Pop a screen from the stack.
*/
pop(count?: number): void;
/**
* Pop to the first route in the stack, dismissing all other screens.
*/
popToTop(): void;
};
StackActionHelpers does contain replace action in it. How did you test that this PR is not working @punisher97 ?
@WoLewicki I use:
import type { NativeStackNavigationProp } from 'react-native-screens/native-stack';
type Props = {
navigation: NativeStackNavigationProp<any>;
};
How add 鈥榬eplace' in NativeStackNavigationProp or which I should use?
EDIT: the PR working I need add long type its so confused for me, because I think NativeStackNavigationProp must be working, thanks:
typescript
type Props = { navigation : NavigationProp<any> & StackActionHelpers<ParamListBase> }
@punisher97 note that this fix has not been released yet. Make sure that you are using the correct reference of react-native-screens when trying to test these changes.
@WoLewicki can we get this included in a release soon? 馃槆
@sbalay 2.15.0 is out 馃帀
Most helpful comment
Oh I can see what is the problem now. Can you check if #695 fixes this?