1 | {"version":3,"names":["React","useState","useNavigation","useIsFocused","navigation","isFocused","setIsFocused","valueToReturn","useEffect","unsubscribeFocus","addListener","unsubscribeBlur","useDebugValue"],"sources":["useIsFocused.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useState } from 'react';\n\nimport useNavigation from './useNavigation';\n\n/**\n * Hook to get the current focus state of the screen. Returns a `true` if screen is focused, otherwise `false`.\n * This can be used if a component needs to render something based on the focus state.\n */\nexport default function useIsFocused(): boolean {\n const navigation = useNavigation();\n const [isFocused, setIsFocused] = useState(navigation.isFocused);\n\n const valueToReturn = navigation.isFocused();\n\n if (isFocused !== valueToReturn) {\n // If the value has changed since the last render, we need to update it.\n // This could happen if we missed an update from the event listeners during re-render.\n // React will process this update immediately, so the old subscription value won't be committed.\n // It is still nice to avoid returning a mismatched value though, so let's override the return value.\n // This is the same logic as in https://github.com/facebook/react/tree/master/packages/use-subscription\n setIsFocused(valueToReturn);\n }\n\n React.useEffect(() => {\n const unsubscribeFocus = navigation.addListener('focus', () =>\n setIsFocused(true)\n );\n\n const unsubscribeBlur = navigation.addListener('blur', () =>\n setIsFocused(false)\n );\n\n return () => {\n unsubscribeFocus();\n unsubscribeBlur();\n };\n }, [navigation]);\n\n React.useDebugValue(valueToReturn);\n\n return valueToReturn;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,QAAyB,OAAzB;AAEA,OAAOC,aAAP,MAA0B,iBAA1B;AAEA;AACA;AACA;AACA;;AACA,eAAe,SAASC,YAAT,GAAiC;EAC9C,MAAMC,UAAU,GAAGF,aAAa,EAAhC;EACA,MAAM,CAACG,SAAD,EAAYC,YAAZ,IAA4BL,QAAQ,CAACG,UAAU,CAACC,SAAZ,CAA1C;EAEA,MAAME,aAAa,GAAGH,UAAU,CAACC,SAAX,EAAtB;;EAEA,IAAIA,SAAS,KAAKE,aAAlB,EAAiC;IAC/B;IACA;IACA;IACA;IACA;IACAD,YAAY,CAACC,aAAD,CAAZ;EACD;;EAEDP,KAAK,CAACQ,SAAN,CAAgB,MAAM;IACpB,MAAMC,gBAAgB,GAAGL,UAAU,CAACM,WAAX,CAAuB,OAAvB,EAAgC,MACvDJ,YAAY,CAAC,IAAD,CADW,CAAzB;IAIA,MAAMK,eAAe,GAAGP,UAAU,CAACM,WAAX,CAAuB,MAAvB,EAA+B,MACrDJ,YAAY,CAAC,KAAD,CADU,CAAxB;IAIA,OAAO,MAAM;MACXG,gBAAgB;MAChBE,eAAe;IAChB,CAHD;EAID,CAbD,EAaG,CAACP,UAAD,CAbH;EAeAJ,KAAK,CAACY,aAAN,CAAoBL,aAApB;EAEA,OAAOA,aAAP;AACD"} |