mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-25 21:15:26 +08:00
docs: add JSDoc for all library exports
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import shortid from 'shortid';
|
||||
import { CommonAction, NavigationState } from './types';
|
||||
|
||||
/**
|
||||
* Base router object that can be used when writing custom routers.
|
||||
* This provides few helper methods to handle common actions such as `RESET`.
|
||||
*/
|
||||
const BaseRouter = {
|
||||
getStateForAction<State extends NavigationState>(
|
||||
state: State,
|
||||
|
||||
@@ -69,7 +69,16 @@ const getPartialState = (
|
||||
};
|
||||
};
|
||||
|
||||
function NavigationContainer(
|
||||
/**
|
||||
* Container component which holds the navigation state.
|
||||
* This should be rendered at the root wrapping the whole app.
|
||||
*
|
||||
* @param props.initialState Initial state object for the navigation tree.
|
||||
* @param props.onStateChange Callback which is called with the latest navigation state when it changes.
|
||||
* @param props.children Child elements to render the content.
|
||||
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
||||
*/
|
||||
const Container = React.forwardRef(function NavigationContainer(
|
||||
{ initialState, onStateChange, children }: Props,
|
||||
ref: React.Ref<NavigationHelpers<ParamListBase>>
|
||||
) {
|
||||
@@ -185,6 +194,6 @@ function NavigationContainer(
|
||||
</NavigationBuilderContext.Provider>
|
||||
</NavigationStateContext.Provider>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default React.forwardRef(NavigationContainer);
|
||||
export default Container;
|
||||
|
||||
@@ -2,17 +2,24 @@ import * as React from 'react';
|
||||
import Screen from './Screen';
|
||||
import { ParamListBase, RouteConfig, TypedNavigator } from './types';
|
||||
|
||||
/**
|
||||
* Higher order component to create a `Navigator` and `Screen` pair.
|
||||
* Custom navigators should wrap the navigator component in `createNavigator` before exporting.
|
||||
*
|
||||
* @param NavigatorComponent The navigtor component to wrap.
|
||||
* @returns Factory method to create a `Navigator` and `Screen` pair.
|
||||
*/
|
||||
export default function createNavigator<
|
||||
ScreenOptions extends object,
|
||||
N extends React.ComponentType<any>
|
||||
>(RawNavigator: N) {
|
||||
return function Navigator<ParamList extends ParamListBase>(): TypedNavigator<
|
||||
>(NavigatorComponent: N) {
|
||||
return <ParamList extends ParamListBase>(): TypedNavigator<
|
||||
ParamList,
|
||||
ScreenOptions,
|
||||
typeof RawNavigator
|
||||
> {
|
||||
typeof NavigatorComponent
|
||||
> => {
|
||||
return {
|
||||
Navigator: RawNavigator,
|
||||
Navigator: NavigatorComponent,
|
||||
Screen: Screen as React.ComponentType<
|
||||
RouteConfig<ParamList, keyof ParamList, ScreenOptions>
|
||||
>,
|
||||
|
||||
@@ -3,6 +3,13 @@ import useNavigation from './useNavigation';
|
||||
|
||||
type EffectCallback = (() => undefined) | (() => () => void);
|
||||
|
||||
/**
|
||||
* Hook to an effect in a focused screen, similar to `React.useEffect`.
|
||||
* This can be used to perform side-effects such as fetching data or subscribing to events.
|
||||
* The passed callback should be wrapped in `React.useCallback` to avoid running the effect too often.
|
||||
*
|
||||
* @param callback Memoized callback containing the effect, should optionally return a cleanup function.
|
||||
*/
|
||||
export default function useFocusEffect(callback: EffectCallback) {
|
||||
const navigation = useNavigation();
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@ import * as React from 'react';
|
||||
import NavigationContext from './NavigationContext';
|
||||
import { NavigationProp, ParamListBase } from './types';
|
||||
|
||||
/**
|
||||
* Hook to access the navigation prop of the parent screen anywhere.
|
||||
*
|
||||
* @returns Navigation prop of the parent screen.
|
||||
*/
|
||||
export default function useNavigation<
|
||||
T extends NavigationProp<ParamListBase>
|
||||
>(): T {
|
||||
|
||||
@@ -57,6 +57,13 @@ const getRouteConfigsFromChildren = <ScreenOptions extends object>(
|
||||
);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Hook for building navigators.
|
||||
*
|
||||
* @param createRouter Factory method which returns router object.
|
||||
* @param options Options object containing `children` and additional options for the router.
|
||||
* @returns An object containing `state`, `navigation`, `descriptors` objects.
|
||||
*/
|
||||
export default function useNavigationBuilder<
|
||||
State extends NavigationState,
|
||||
ScreenOptions extends object,
|
||||
|
||||
Reference in New Issue
Block a user