Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed May 28, 2024
1 parent c07d6d2 commit 4c1a982
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/kernel/logger/adapters/sentry.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Native as Sentry} from 'sentry-expo'
export * as Sentry from '@sentry/react-native'
25 changes: 18 additions & 7 deletions apps/wallet-mobile/src/kernel/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NavigationProp,
NavigationState,
NavigatorScreenParams,
ParamListBase,
RouteProp,
useNavigation,
useNavigationState,
Expand Down Expand Up @@ -624,7 +625,10 @@ function useKeepRoutesInHistory(routesToKeep: string[]) {
if (currentRouteId !== initialRouteId) {
return
}
const {routes} = navigation.getState()
const state = navigation.getState()
if (!state) return

const {routes} = state
const currentRouteNames = routes.map((r) => r.name)

if (compareArrays(currentRouteNames, routesToKeep)) {
Expand All @@ -639,7 +643,9 @@ function useKeepRoutesInHistory(routesToKeep: string[]) {
routes: newRoutes.map((r) => ({...r, state: undefined})),
routeNames: newRoutes.map((r) => r.name),
}
navigation.reset(newState)
// Type 'string[]' is not assignable to type '(keyof RootParamList)[]'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
navigation.reset(newState as any)
})

return () => task.cancel()
Expand All @@ -656,7 +662,7 @@ export const useIsRouteActive = () => {
export function useOverridePreviousRoute<RouteName extends string>(previousRouteName: RouteName) {
const navigation = useNavigation()
const [initialRouteName] = React.useState(() => getNavigationRouteName(navigation))
const allRouteNames: string[] = navigation.getState().routes.map((route) => route.name)
const allRouteNames: string[] = navigation.getState()?.routes.map((route) => route.name) ?? ['']
const previousRouteIndex = allRouteNames.indexOf(previousRouteName)
const currentRouteIndex = allRouteNames.indexOf(initialRouteName)

Expand All @@ -673,13 +679,18 @@ export function useOverridePreviousRoute<RouteName extends string>(previousRoute
useKeepRoutesInHistory(newRoutes)
}

function getNavigationRouteId(navigation: NavigationProp<ReactNavigation.RootParamList>) {
// https://github.com/react-navigation/react-navigation/issues/11893
type Navigation = Omit<NavigationProp<ParamListBase, string>, 'getState'> & {
getState(): NavigationState | undefined
}

function getNavigationRouteId(navigation: Navigation) {
const state = navigation.getState()
return state.routes[state.index].key
return state?.routes[state.index].key
}

function getNavigationRouteName(navigation: NavigationProp<ReactNavigation.RootParamList>) {
function getNavigationRouteName(navigation: Navigation) {
return selectRouteName(navigation.getState())
}

const selectRouteName = (state: NavigationState) => state.routes[state.index].name
const selectRouteName = (state?: NavigationState) => state?.routes[state.index].name ?? ''

0 comments on commit 4c1a982

Please sign in to comment.