From dd345871f849ad7c3a4abd353a3931e6422f63ef Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 21 Mar 2021 13:15:43 +0100 Subject: [PATCH] Provide more debugging information through Sentry --- src/Screens.tsx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Screens.tsx b/src/Screens.tsx index 6781fb49..f63b52ac 100644 --- a/src/Screens.tsx +++ b/src/Screens.tsx @@ -45,7 +45,7 @@ const Screens: React.FC = ({ localCorrupt }) => { dark = 'light-content' } - const routeNameRef = useRef() + const routeRef = useRef<{ name?: string; params?: {} }>() const isConnected = useNetInfo().isConnected useEffect(() => { @@ -114,30 +114,32 @@ const Screens: React.FC = ({ localCorrupt }) => { }, [instanceActive]) // Callbacks - const navigationContainerOnReady = useCallback( - () => - (routeNameRef.current = navigationRef.current?.getCurrentRoute()?.name), - [] - ) + const navigationContainerOnReady = useCallback(() => { + const currentRoute = navigationRef.current?.getCurrentRoute() + routeRef.current = { + name: currentRoute?.name, + params: currentRoute?.params + } + }, []) const navigationContainerOnStateChange = useCallback(() => { - const previousRouteName = routeNameRef.current - const currentRouteName = navigationRef.current?.getCurrentRoute()?.name + const previousRoute = routeRef.current + const currentRoute = navigationRef.current?.getCurrentRoute() - const matchTabName = currentRouteName?.match(/(Tab-.*)-Root/) + const matchTabName = currentRoute?.name?.match(/(Tab-.*)-Root/) if (matchTabName) { //@ts-ignore dispatch(updatePreviousTab(matchTabName[1])) } - if (previousRouteName !== currentRouteName) { - Analytics.setCurrentScreen(currentRouteName) + if (previousRoute?.name !== currentRoute?.name) { + Analytics.setCurrentScreen(currentRoute?.name) Sentry.Native.setContext('page', { - previous: previousRouteName, - current: currentRouteName + previous: previousRoute, + current: currentRoute }) } - routeNameRef.current = currentRouteName + routeRef.current = currentRoute }, []) return (