UNPKG

2.59 kBSource Map (JSON)View Raw
1{"version":3,"names":["MULTIPLE_NAVIGATOR_ERROR","SingleNavigatorContext","React","createContext","undefined","EnsureSingleNavigator","children","navigatorKeyRef","useRef","value","useMemo","register","key","currentKey","current","Error","unregister"],"sources":["EnsureSingleNavigator.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype Props = {\n children: React.ReactNode;\n};\n\nconst MULTIPLE_NAVIGATOR_ERROR = `Another navigator is already registered for this container. You likely have multiple navigators under a single \"NavigationContainer\" or \"Screen\". Make sure each navigator is under a separate \"Screen\" container. See https://reactnavigation.org/docs/nesting-navigators for a guide on nesting.`;\n\nexport const SingleNavigatorContext = React.createContext<\n | {\n register(key: string): void;\n unregister(key: string): void;\n }\n | undefined\n>(undefined);\n\n/**\n * Component which ensures that there's only one navigator nested under it.\n */\nexport default function EnsureSingleNavigator({ children }: Props) {\n const navigatorKeyRef = React.useRef<string | undefined>();\n\n const value = React.useMemo(\n () => ({\n register(key: string) {\n const currentKey = navigatorKeyRef.current;\n\n if (currentKey !== undefined && key !== currentKey) {\n throw new Error(MULTIPLE_NAVIGATOR_ERROR);\n }\n\n navigatorKeyRef.current = key;\n },\n unregister(key: string) {\n const currentKey = navigatorKeyRef.current;\n\n if (key !== currentKey) {\n return;\n }\n\n navigatorKeyRef.current = undefined;\n },\n }),\n []\n );\n\n return (\n <SingleNavigatorContext.Provider value={value}>\n {children}\n </SingleNavigatorContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAAA;;;;;;AAMA,MAAMA,wBAAwB,GAAI,oSAAlC;AAEO,MAAMC,sBAAsB,gBAAGC,KAAK,CAACC,aAAN,CAMpCC,SANoC,CAA/B;AAQP;AACA;AACA;;;;AACe,SAASC,qBAAT,OAAoD;EAAA,IAArB;IAAEC;EAAF,CAAqB;EACjE,MAAMC,eAAe,GAAGL,KAAK,CAACM,MAAN,EAAxB;EAEA,MAAMC,KAAK,GAAGP,KAAK,CAACQ,OAAN,CACZ,OAAO;IACLC,QAAQ,CAACC,GAAD,EAAc;MACpB,MAAMC,UAAU,GAAGN,eAAe,CAACO,OAAnC;;MAEA,IAAID,UAAU,KAAKT,SAAf,IAA4BQ,GAAG,KAAKC,UAAxC,EAAoD;QAClD,MAAM,IAAIE,KAAJ,CAAUf,wBAAV,CAAN;MACD;;MAEDO,eAAe,CAACO,OAAhB,GAA0BF,GAA1B;IACD,CATI;;IAULI,UAAU,CAACJ,GAAD,EAAc;MACtB,MAAMC,UAAU,GAAGN,eAAe,CAACO,OAAnC;;MAEA,IAAIF,GAAG,KAAKC,UAAZ,EAAwB;QACtB;MACD;;MAEDN,eAAe,CAACO,OAAhB,GAA0BV,SAA1B;IACD;;EAlBI,CAAP,CADY,EAqBZ,EArBY,CAAd;EAwBA,oBACE,oBAAC,sBAAD,CAAwB,QAAxB;IAAiC,KAAK,EAAEK;EAAxC,GACGH,QADH,CADF;AAKD"}
\No newline at end of file