Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | 1x 1x 2x 1x 1x 1x 4x 4x 4x 1x 2x 2x 2x 2x 1x 2x 2x | import React, { lazy, Suspense } from 'react';
import ErrorBoundary from 'react-native-error-boundary';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ActivityIndicator, Text, TouchableOpacity, View } from 'react-native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { HomeIcon } from '@repo/ui/icons/Home';
import { MenuIcon } from '@repo/ui/icons/Menu';
import { UserIcon } from '@repo/ui/icons/User';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { SCREENS } from '@repo/constants/screens';
import { FallbackError } from '@/components/FallbackError';
import { HomeScreen } from '../screens';
const MyRequestScreen = lazy(() =>
import('../screens/MyRequest').then(module => ({ default: module.MyRequestScreen })),
);
const ProfileScreen = lazy(() =>
import('../screens/Profile').then(module => ({ default: module.ProfileScreen })),
);
import { useTheme } from '@repo/ui/themes/ThemeContext';
import { AppStackScreenProps, BottomTabParamList } from '../types';
const withSuspense = (Component: React.ComponentType<any>) => (props: any) => {
const styles = useStyles();
return (
<ErrorBoundary FallbackComponent={FallbackError}>
<Suspense
fallback={
<View style={styles.loadingContainer}>
<ActivityIndicator size="small" />
</View>
}
>
<Component {...props} />
</Suspense>
</ErrorBoundary>
);
};
const LazyMyRequestScreen = withSuspense(MyRequestScreen);
const LazyProfileScreen = withSuspense(ProfileScreen);
type BottomTabProps = AppStackScreenProps<typeof SCREENS.BOTTOM_TAB>;
const Tab = createBottomTabNavigator<BottomTabParamList>();
const HomeIconComponent = ({ focused }: { focused: boolean }) => <HomeIcon isActive={focused} />;
const MenuIconComponent = ({ focused }: { focused: boolean }) => <MenuIcon isActive={focused} />;
const UserIconComponent = ({ focused }: { focused: boolean }) => <UserIcon isActive={focused} />;
const BottomTab = ({ navigation }: BottomTabProps) => {
const insets = useSafeAreaInsets();
const { theme } = useTheme();
const styles = useStyles();
const handlePressFab = () => {
navigation.navigate(SCREENS.NEW_REQUEST);
};
return (
<View style={styles.container}>
<Tab.Navigator
safeAreaInsets={{ bottom: 0 }}
initialRouteName={SCREENS.HOME}
screenOptions={{
headerShown: false,
tabBarShowLabel: true,
animation: 'fade',
tabBarStyle: {
height: theme.metrics.spacing[15] + insets.bottom,
paddingTop: theme.metrics.spacing[1],
},
}}
>
<Tab.Screen
name={SCREENS.HOME}
component={HomeScreen}
options={{
title: 'Home',
tabBarIcon: HomeIconComponent,
}}
/>
<Tab.Screen
name={SCREENS.MY_REQUEST}
component={LazyMyRequestScreen}
options={{
title: 'My Request',
tabBarIcon: MenuIconComponent,
}}
/>
<Tab.Screen
name={SCREENS.PROFILE}
component={LazyProfileScreen}
options={{
title: 'Profile',
tabBarIcon: UserIconComponent,
}}
/>
</Tab.Navigator>
<TouchableOpacity
style={styles.fab}
onPress={handlePressFab}
accessible={true}
accessibilityRole="button"
accessibilityLabel="Create new request"
accessibilityHint="Navigates to the New Request screen"
>
<Text style={styles.plus}>+</Text>
</TouchableOpacity>
</View>
);
};
const useStyles = makeStyles(theme => ({
container: {
flex: 1,
},
plus: {
fontSize: theme.metrics.textSize[30],
color: theme.colors.text.white,
},
fab: {
position: 'absolute',
bottom: theme.metrics.spacing[25],
right: theme.metrics.spacing[5],
width: theme.metrics.spacing[15],
height: theme.metrics.spacing[15],
borderRadius: theme.metrics.borderRadius[6],
backgroundColor: theme.colors.background.primary,
justifyContent: 'center',
alignItems: 'center',
shadowColor: theme.colors.shadow.default,
shadowOffset: { width: theme.metrics.spacing[0], height: theme.metrics.spacing[1] },
shadowOpacity: theme.metrics.opacity[30],
shadowRadius: theme.metrics.spacing[1],
elevation: 5,
},
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
}));
export default BottomTab;
|