58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
import { NavigationProp, NavigationState } from '@react-navigation/native';
|
|
import { Href } from './types';
|
|
/**
|
|
* Returns the underlying React Navigation [`navigation` object](https://reactnavigation.org/docs/navigation-object)
|
|
* to imperatively access layout-specific functionality like `navigation.openDrawer()` in a
|
|
* [Drawer](/router/advanced/drawer/) layout.
|
|
*
|
|
* @example
|
|
* ```tsx app/index.tsx
|
|
* import { useNavigation } from 'expo-router';
|
|
*
|
|
* export default function Route() {
|
|
* // Access the current navigation object for the current route.
|
|
* const navigation = useNavigation();
|
|
*
|
|
* return (
|
|
* <View>
|
|
* <Text onPress={() => {
|
|
* // Open the drawer view.
|
|
* navigation.openDrawer();
|
|
* }}>
|
|
* Open Drawer
|
|
* </Text>
|
|
* </View>
|
|
* );
|
|
* }
|
|
* ```
|
|
*
|
|
* When using nested layouts, you can access higher-order layouts by passing a secondary argument denoting the layout route.
|
|
* For example, `/menu/_layout.tsx` is nested inside `/app/orders/`, you can use `useNavigation('/orders/menu/')`.
|
|
*
|
|
* @example
|
|
* ```tsx app/orders/menu/index.tsx
|
|
* import { useNavigation } from 'expo-router';
|
|
*
|
|
* export default function MenuRoute() {
|
|
* const rootLayout = useNavigation('/');
|
|
* const ordersLayout = useNavigation('/orders');
|
|
*
|
|
* // Same as the default results of `useNavigation()` when invoked in this route.
|
|
* const parentLayout = useNavigation('/orders/menu');
|
|
* }
|
|
* ```
|
|
*
|
|
* If you attempt to access a layout that doesn't exist, an error such as
|
|
* `Could not find parent navigation with route "/non-existent"` is thrown.
|
|
*
|
|
*
|
|
* @param parent Provide an absolute path such as `/(root)` to the parent route or a relative path like `../../` to the parent route.
|
|
* @returns The navigation object for the current route.
|
|
*
|
|
* @see React Navigation documentation on [navigation dependent functions](https://reactnavigation.org/docs/navigation-object/#navigator-dependent-functions)
|
|
* for more information.
|
|
*/
|
|
export declare function useNavigation<T = Omit<NavigationProp<ReactNavigation.RootParamList>, 'getState'> & {
|
|
getState(): NavigationState | undefined;
|
|
}>(parent?: string | Href): T;
|
|
//# sourceMappingURL=useNavigation.d.ts.map
|