Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/(tabs)/(home)/scanning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<>
<Stack.Screen
Expand All @@ -118,6 +132,17 @@ export default function ScanningScreen() {
headerTitleStyle: { ...Typography.title, color: Colors.brand.text },
headerTintColor: Colors.brand.text,
headerShadowVisible: false,
headerBackVisible: !isScanning,
gestureEnabled: !isScanning,
headerLeft: isScanning
? () => (
<AppIcon
name="back"
disabled
style={styles.headerBackButton}
/>
)
: undefined,
}}
/>
<View
Expand Down Expand Up @@ -330,6 +355,10 @@ const styles = StyleSheet.create({
paddingHorizontal: 24,
paddingTop: 40,
},
headerBackButton: {
width: 44,
height: 44,
},
containerCompact: {
paddingTop: 20,
},
Expand Down
27 changes: 27 additions & 0 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,36 @@ const TAB_TO_HREF: Partial<Record<TabVariant, string>> = {
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);
Expand All @@ -36,6 +60,9 @@ function CustomTabBar({ state }: BottomTabBarProps) {
<BottomTabBar
activeTab={activeTab}
onTabPress={handleTabPress}
home={{ disabled: isScanningRoute }}
addLink={{ disabled: isScanningRoute }}
folder={{ disabled: isScanningRoute }}
/>
);
}
Expand Down
Loading