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,GAAG,KAAK,CAAC;QAC7B,6BAA6B,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACzF,6BAA6B,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAEhG,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,IAAI;SACZ,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,wBAAwB,CAAC,MAAa;QAC3C,IAAI,oBAAoB,EAAE;YACxB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SACxB;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,UAAe;QAC7C,IAAI,oBAAoB,EAAE;YACxB,aAAa,EAAE,CAAC;SACjB;QAED,MAAM,KAAK,CAAC;IACd,CAAC;IA2BD,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACpB,OAAO,IAAI,CAAC;SACb;aAAM;YACL,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;SAC5B;IACH,CAAC;CACF","sourcesContent":["import React from 'react';\nimport { NativeModules } from 'react-native';\n\nimport { getAppLoadingLifecycleEmitter } from './AppLoading';\n\nconst { ExponentAppLoadingManager } = NativeModules;\n\nasync function finishedAsync(): Promise<any> {\n if (ExponentAppLoadingManager && ExponentAppLoadingManager.finishedAsync) {\n return await ExponentAppLoadingManager.finishedAsync();\n }\n}\n\ntype Props = {\n children: React.ReactNode;\n};\n\ntype State = {\n error: Error | null;\n};\n\n// Store this outside of the component so it is available inside getDerivedStateFromError\nlet _appLoadingIsMounted: boolean;\n\n/**\n * This component is never rendered in production!\n *\n * In production the app will just hard crash on errors, unless the developer\n * decides to handle them by overriding the global error handler and swallowing\n * the error, in which case they are responsible for determining how to recover\n * from this state.\n *\n * - The sole purpose of this component is to hide the splash screen if an\n * error occurs that prevents it from being hidden. Please note that this\n * currently only works with <AppLoading /> and not SplashScreen.preventAutoHide()!\n * - We only want to update the error state when the splash screen is visible, after\n * the splash screen is gone we don't want to do anything in this component.\n * - On Android it is necessary for us to render some content in order to hide\n * the splash screen, just calling `ExponentAppLoadingManager.finishedAsync()`\n * is not sufficient.\n *\n */\nexport default class RootErrorBoundary extends React.Component<Props, State> {\n constructor(props: Props) {\n super(props);\n\n _appLoadingIsMounted = false;\n getAppLoadingLifecycleEmitter().once('componentDidMount', this._subscribeToGlobalErrors);\n getAppLoadingLifecycleEmitter().once('componentWillUnmount', this._unsubscribeFromGlobalErrors);\n\n this.state = {\n error: null,\n };\n }\n\n /**\n * Test this by adding `throw new Error('example')` to your root component\n * when the AppLoading component is rendered.\n */\n static getDerivedStateFromError(_error: Error) {\n if (_appLoadingIsMounted) {\n return { error: true };\n }\n\n return null;\n }\n\n componentDidCatch(error: Error, _errorInfo: any) {\n if (_appLoadingIsMounted) {\n finishedAsync();\n }\n\n throw error;\n }\n\n _subscribeToGlobalErrors = () => {\n _appLoadingIsMounted = true;\n\n const originalErrorHandler = ErrorUtils.getGlobalHandler();\n\n ErrorUtils.setGlobalHandler((error, isFatal) => {\n if (_appLoadingIsMounted) {\n finishedAsync();\n\n if (isFatal) {\n this.setState({ error });\n }\n }\n\n originalErrorHandler(error, isFatal);\n });\n };\n\n _unsubscribeFromGlobalErrors = () => {\n // We don't remove the global error handler that we set here because it is conceivable that the\n // user may add error handlers *after* we subscribe, and we don't want to override those, so\n // instead we just gate the call\n _appLoadingIsMounted = false;\n };\n\n render() {\n if (this.state.error) {\n return null;\n } else {\n return this.props.children;\n }\n }\n}\n"]}
\No newline at end of file