UNPKG

2.25 kBSource Map (JSON)View Raw
1{"version":3,"names":["useOnRouteFocus","router","getState","key","sourceRouteKey","setState","onRouteFocus","onRouteFocusParent","React","useContext","NavigationBuilderContext","useCallback","state","result","getStateForRouteFocus","undefined"],"sources":["useOnRouteFocus.tsx"],"sourcesContent":["import type {\n NavigationAction,\n NavigationState,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext from './NavigationBuilderContext';\n\ntype Options<Action extends NavigationAction> = {\n router: Router<NavigationState, Action>;\n getState: () => NavigationState;\n setState: (state: NavigationState) => void;\n key?: string;\n};\n\n/**\n * Hook to handle focus actions for a route.\n * Focus action needs to be treated specially, coz when a nested route is focused,\n * the parent navigators also needs to be focused.\n */\nexport default function useOnRouteFocus<Action extends NavigationAction>({\n router,\n getState,\n key: sourceRouteKey,\n setState,\n}: Options<Action>) {\n const { onRouteFocus: onRouteFocusParent } = React.useContext(\n NavigationBuilderContext\n );\n\n return React.useCallback(\n (key: string) => {\n const state = getState();\n const result = router.getStateForRouteFocus(state, key);\n\n if (result !== state) {\n setState(result);\n }\n\n if (onRouteFocusParent !== undefined && sourceRouteKey !== undefined) {\n onRouteFocusParent(sourceRouteKey);\n }\n },\n [getState, onRouteFocusParent, router, setState, sourceRouteKey]\n );\n}\n"],"mappings":";;;;;;;AAKA;;AAEA;;;;;;;;AASA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,OAKK;EAAA,IALqD;IACvEC,MADuE;IAEvEC,QAFuE;IAGvEC,GAAG,EAAEC,cAHkE;IAIvEC;EAJuE,CAKrD;EAClB,MAAM;IAAEC,YAAY,EAAEC;EAAhB,IAAuCC,KAAK,CAACC,UAAN,CAC3CC,iCAD2C,CAA7C;EAIA,OAAOF,KAAK,CAACG,WAAN,CACJR,GAAD,IAAiB;IACf,MAAMS,KAAK,GAAGV,QAAQ,EAAtB;IACA,MAAMW,MAAM,GAAGZ,MAAM,CAACa,qBAAP,CAA6BF,KAA7B,EAAoCT,GAApC,CAAf;;IAEA,IAAIU,MAAM,KAAKD,KAAf,EAAsB;MACpBP,QAAQ,CAACQ,MAAD,CAAR;IACD;;IAED,IAAIN,kBAAkB,KAAKQ,SAAvB,IAAoCX,cAAc,KAAKW,SAA3D,EAAsE;MACpER,kBAAkB,CAACH,cAAD,CAAlB;IACD;EACF,CAZI,EAaL,CAACF,QAAD,EAAWK,kBAAX,EAA+BN,MAA/B,EAAuCI,QAAvC,EAAiDD,cAAjD,CAbK,CAAP;AAeD"}
\No newline at end of file