import * as Sentry from '@sentry/react-native' ; import type { NavigationState } from 'react-navigation' ; function getCurrentRouteName ( navigationState ) { if ( ! navigationState ) { return null ; } const route = navigationState . routes [ navigationState . index ] ; if ( route . routes ) { return getCurrentRouteName ( route ) ; } return route . routeName ; } export function trackScreenChanges ( prevState , currentState ) { const currentScreen = getCurrentRouteName ( currentState ) ; const prevScreen = getCurrentRouteName ( prevState ) ; if ( ! currentScreen ) { return ; } if ( currentScreen !== prevScreen ) { Sentry . addBreadcrumb ( { message : `Navigated to ${ currentScreen }` , category : 'navigation' , data : { prev : prevScreen , } , } ) ; } }