diff --git a/app/(tabs)/(home)/scanning.tsx b/app/(tabs)/(home)/scanning.tsx index d8566c4..7ce25b5 100644 --- a/app/(tabs)/(home)/scanning.tsx +++ b/app/(tabs)/(home)/scanning.tsx @@ -2,12 +2,13 @@ import { useAuth } from '@clerk/expo'; import LottieView from 'lottie-react-native'; import { router, Stack, useLocalSearchParams } from 'expo-router'; import { useEffect, useRef, useState } from 'react'; -import { StyleSheet, Text, TouchableOpacity, useWindowDimensions, View } from 'react-native'; +import { BackHandler, StyleSheet, Text, TouchableOpacity, useWindowDimensions, View } from 'react-native'; import { useBottomTabBarHeight } from '@react-navigation/bottom-tabs'; import { fetchAnalysis, requestAnalysis, type AnalysisResponse, type AnalysisVerdict } from '@/api/analyses'; import { ApiError } from '@/api/api-client'; import { Colors, Typography } from '@/constants/theme'; +import { AppIcon } from '@/components/ui/app-icon'; import { useGuardedPress } from '@/utils/press-guard'; const POLLING_INTERVAL_MS = 2_000; @@ -104,9 +105,22 @@ export default function ScanningScreen() { }, [isLoaded, isSignedIn, retryKey, url]); const hasError = errorMessage.length > 0; + const isScanning = !hasError; const guardedRetry = useGuardedPress(() => setRetryKey((key) => key + 1)); const guardedBack = useGuardedPress(() => router.back()); + useEffect(() => { + if (!isScanning) { + return undefined; + } + + const subscription = BackHandler.addEventListener('hardwareBackPress', () => true); + + return () => { + subscription.remove(); + }; + }, [isScanning]); + return ( <> ( + + ) + : undefined, }} /> > = { folder: '/(tabs)/(folder)', }; +type NestedRoute = { + name?: string; + state?: { + index?: number; + routes?: NestedRoute[]; + }; +}; + +function getActiveNestedRouteName(route?: NestedRoute): string | undefined { + const nestedState = route?.state; + + if (!nestedState?.routes?.length) { + return route?.name; + } + + const nestedIndex = nestedState.index ?? 0; + return getActiveNestedRouteName(nestedState.routes[nestedIndex]); +} + function CustomTabBar({ state }: BottomTabBarProps) { const activeRoute = state.routes[state.index]; const activeRouteName = activeRoute?.name ?? '(home)'; const activeTab = ROUTE_TO_TAB[activeRouteName] ?? 'home'; + const isScanningRoute = getActiveNestedRouteName(activeRoute as NestedRoute) === 'scanning'; function handleTabPress(tab: TabVariant) { + if (isScanningRoute) { + return; + } + const href = TAB_TO_HREF[tab]; if (href) { router.navigate(href as any); @@ -36,6 +60,9 @@ function CustomTabBar({ state }: BottomTabBarProps) { ); }