UNPKG

2.3 kBSource Map (JSON)View Raw
1{"version":3,"names":["React","NavigationBuilderContext","useOnRouteFocus","router","getState","key","sourceRouteKey","setState","onRouteFocus","onRouteFocusParent","useContext","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,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAAqC,4BAArC;;AASA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAT,OAKK;EAAA,IALqD;IACvEC,MADuE;IAEvEC,QAFuE;IAGvEC,GAAG,EAAEC,cAHkE;IAIvEC;EAJuE,CAKrD;EAClB,MAAM;IAAEC,YAAY,EAAEC;EAAhB,IAAuCT,KAAK,CAACU,UAAN,CAC3CT,wBAD2C,CAA7C;EAIA,OAAOD,KAAK,CAACW,WAAN,CACJN,GAAD,IAAiB;IACf,MAAMO,KAAK,GAAGR,QAAQ,EAAtB;IACA,MAAMS,MAAM,GAAGV,MAAM,CAACW,qBAAP,CAA6BF,KAA7B,EAAoCP,GAApC,CAAf;;IAEA,IAAIQ,MAAM,KAAKD,KAAf,EAAsB;MACpBL,QAAQ,CAACM,MAAD,CAAR;IACD;;IAED,IAAIJ,kBAAkB,KAAKM,SAAvB,IAAoCT,cAAc,KAAKS,SAA3D,EAAsE;MACpEN,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