@redshank/native-router
Version:
@redshank/native-router is a file-based router for React Native CLI
70 lines • 3.35 kB
TypeScript
import { type ParamListBase } from '@react-navigation/native';
type Keyof<T extends {}> = Extract<keyof T, string>;
export type To<ParamList extends ReactNavigation.RootParamList = ReactNavigation.RootParamList, RouteName extends keyof ParamList = Keyof<ParamList>> = RouteName | (undefined extends ParamList[RouteName] ? {
screen: Extract<RouteName, string>;
params?: ParamList[RouteName];
merge?: boolean;
} : {
screen: Extract<RouteName, string>;
params: ParamList[RouteName];
merge?: boolean;
});
export type Router<ParamList extends ParamListBase, RouteName extends Keyof<ParamList> = Keyof<ParamList>, ScreenOptions extends {} = {}> = {
/**
* Navigate to a route in the navigation tree.
*/
navigate: <T extends ParamList = ParamList>(to: To<T>) => void;
/**
* The push action adds a route on top of the stack and navigates forward to it.
* This differs from navigate in that navigate will pop back to earlier in the stack if a route of the given name
* is already present there. push will always add on top, so a route can be present multiple times.
*/
push: <T extends ParamList = ParamList>(to: To<T>) => void;
/**
* Replace a route in the navigation tree
*/
replace: <T extends ParamList = ParamList>(to: To<T>) => void;
/**
* Check if dispatching back action will be handled by navigation.
* Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.
*/
canGoBack: () => boolean;
/**
* Check if the screen is focused. The method returns `true` if focused, `false` otherwise.
* Note that this method doesn't re-render screen when the focus changes. So don't use it in `render`.
* To get notified of focus changes, use `addListener('focus', cb)` and `addListener('blur', cb)`.
* To conditionally render content based on focus state, use the `useIsFocused` hook.
*/
isFocused: () => boolean;
/**
* Go back to the previous route in history.
*/
back: () => void;
/**
* The pop action takes you back to a previous screen in the stack.
* It takes one optional argument (count), which allows you to specify how many screens to pop back by.
*/
pop: (count: number) => void;
/**
* The popToTop action takes you back to the first screen in the stack, dismissing all the others.
* It's functionally identical to StackActions.pop({n: currentIndex}).
*/
popToTop: () => void;
/**
* Update the param object for the route.
* The new params will be shallow merged with the old one.
*
* @param params Params object for the current route.
*/
setParams(params: ParamList[RouteName] extends undefined ? undefined : Partial<ParamList[RouteName]>): void;
/**
* Update the options for the route.
* The options object will be shallow merged with default options object.
*
* @param options Options object for the route.
*/
setOptions(options: Partial<ScreenOptions>): void;
};
declare const useRouter: <ParamList extends ParamListBase, RouteName extends Keyof<ParamList> = Extract<keyof ParamList, string>, ScreenOptions extends {} = {}>() => Router<ParamList, RouteName, ScreenOptions>;
export default useRouter;
//# sourceMappingURL=useRouter.d.ts.map