expo-router
Version:
Expo Router is a file-based router for React Native and web applications.
92 lines (91 loc) • 3.56 kB
TypeScript
import type { NavigationAction } from '../react-navigation';
import type { UnknownOutputParams } from '../types';
/**
* The page that a page mark describes.
*/
export interface RouterPageMarkDetail {
/**
* The pathname of the page, for example `/users/42`.
*/
pathname: string;
/**
* The route and search params of the page.
*/
params: UnknownOutputParams;
/**
* The route segments of the page, for example `['users', '[id]']`.
*/
segments: string[];
/**
* The navigation route key of the screen. It stays the same while the screen is mounted.
*/
screenId: string;
}
/**
* The navigation action that an `expo-router:action-enqueued` or `expo-router:action-dispatched` mark describes.
*/
export interface RouterActionMarkDetail {
/**
* Same value on the `expo-router:action-enqueued` and `expo-router:action-dispatched` marks of one action.
*/
actionId: number;
/**
* The type of the dispatched navigation action, for example `NAVIGATE`.
*/
actionType: NavigationAction['type'];
}
/**
* A performance mark recorded by Expo Router.
* To read `detail`, check its `name` and cast it to the matching mark type, such as
* `RouterPageFocusedMark`.
*/
export interface BaseRouterPerformanceMark<Name extends string, Detail> extends PerformanceMark {
readonly entryType: 'mark';
/**
* The name of the mark, which also determines the shape of `detail`.
*/
readonly name: Name;
/**
* The page or action data of the mark.
*/
readonly detail: Detail;
}
/**
* A screen that rendered as part of a preload (for example, `router.prefetch()`) and is not
* focused. If the user later navigates to it, Expo Router records `expo-router:page-focused`.
*/
export type RouterPagePreloadedMark = BaseRouterPerformanceMark<'expo-router:page-preloaded', RouterPageMarkDetail>;
/**
* A screen became focused, after its content committed.
*/
export type RouterPageFocusedMark = BaseRouterPerformanceMark<'expo-router:page-focused', RouterPageMarkDetail>;
/**
* A focused screen lost focus.
*/
export type RouterPageBlurredMark = BaseRouterPerformanceMark<'expo-router:page-blurred', RouterPageMarkDetail>;
/**
* A screen unmounted, or its route info changed.
*/
export type RouterPageRemovedMark = BaseRouterPerformanceMark<'expo-router:page-removed', RouterPageMarkDetail>;
/**
* Expo Router received a navigation action, before it reduced it. If the action
* changes the navigation state, `expo-router:action-dispatched` marks with the same `actionId`
* follow.
*/
export type RouterActionEnqueuedMark = BaseRouterPerformanceMark<'expo-router:action-enqueued', Pick<RouterActionMarkDetail, 'actionId'>>;
/**
* A navigation action changed the navigation state.
*/
export type RouterActionDispatchedMark = BaseRouterPerformanceMark<'expo-router:action-dispatched', RouterActionMarkDetail>;
/**
* Any performance mark recorded by Expo Router. Check `name` to narrow the type of `detail`.
*/
export type RouterPerformanceMark = RouterPagePreloadedMark | RouterPageFocusedMark | RouterPageBlurredMark | RouterPageRemovedMark | RouterActionEnqueuedMark | RouterActionDispatchedMark;
export type RouterPerformanceMarkName = RouterPerformanceMark['name'];
/**
* The performance mark type with the given `name`, for example
* `RouterPerformanceMarkByName<'expo-router:page-focused'>`.
*/
export type RouterPerformanceMarkByName<Name extends RouterPerformanceMarkName> = Extract<RouterPerformanceMark, {
name: Name;
}>;