import * as Sentry from '@sentry/react-native'
import type {NavigationState} from 'react-navigation'

// gets the current screen from navigation state
function getCurrentRouteName(navigationState: NavigationState): ?string {
	if (!navigationState) {
		return null
	}
	const route = navigationState.routes[navigationState.index]
	// dive into nested navigators
	if (route.routes) {
		return getCurrentRouteName(route)
	}
	return route.routeName
}

export function trackScreenChanges(
	prevState: NavigationState,
	currentState: NavigationState,
) {
	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,
			},
		})
	}
}

import * as Sentry from '@sentry/react-native'
import type {NavigationState} from 'react-navigation'

// gets the current screen from navigation state
function getCurrentRouteName(navigationState: NavigationState): ?string {
	if (!navigationState) {
		return null
	}
	const route = navigationState.routes[navigationState.index]
	// dive into nested navigators
	if (route.routes) {
		return getCurrentRouteName(route)
	}
	return route.routeName
}

export function trackScreenChanges(
	prevState: NavigationState,
	currentState: NavigationState,
): void {
	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,
			},
		})
	}
}

Add an explicit return type to module boundary function
navigation: Add an explicit return type to module boundary function

Signed-off-by: Kristofer Rye <1ed31cfd0b53bc3d1689a6fee6dbfc9507dffd22@gmail.com>
