|
| 1 | +import { faCircle } from '@fortawesome/free-solid-svg-icons'; |
| 2 | +import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'; |
| 3 | +import type { BottomTabNavigationOptions } from '@react-navigation/bottom-tabs'; |
| 4 | +import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; |
| 5 | +import { StyleSheet, Text } from 'react-native'; |
| 6 | +import Sortable from 'react-native-sortables'; |
| 7 | + |
| 8 | +import { FlexCell, Screen, ScrollScreen } from '@/components'; |
| 9 | +import { colors, spacing, text } from '@/theme'; |
| 10 | +import { getCategories } from '@/utils'; |
| 11 | + |
| 12 | +const Tab = createBottomTabNavigator(); |
| 13 | + |
| 14 | +const DATA_LENGTH = 30; |
| 15 | +const DATA = getCategories(DATA_LENGTH); |
| 16 | + |
| 17 | +type FlexProps = { |
| 18 | + data: Array<string>; |
| 19 | +}; |
| 20 | + |
| 21 | +function Flex({ data }: FlexProps) { |
| 22 | + return ( |
| 23 | + <Sortable.Flex columnGap={spacing.sm} rowGap={spacing.xs}> |
| 24 | + {data.map(item => ( |
| 25 | + <FlexCell key={item} size='large'> |
| 26 | + {item} |
| 27 | + </FlexCell> |
| 28 | + ))} |
| 29 | + </Sortable.Flex> |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +function Screen1() { |
| 34 | + return ( |
| 35 | + <ScrollScreen contentContainerStyle={styles.scrollContainer}> |
| 36 | + <Text style={styles.screenTitle}>Screen 1 flex:</Text> |
| 37 | + <Flex data={DATA.slice(0, DATA_LENGTH / 2)} /> |
| 38 | + </ScrollScreen> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +function Screen2() { |
| 43 | + return ( |
| 44 | + <ScrollScreen contentContainerStyle={styles.scrollContainer}> |
| 45 | + <Text style={styles.screenTitle}>Screen 2 flex:</Text> |
| 46 | + <Flex data={DATA.slice(DATA_LENGTH / 2)} /> |
| 47 | + </ScrollScreen> |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +const tabBarOptions: BottomTabNavigationOptions = { |
| 52 | + tabBarIcon: ({ focused }) => ( |
| 53 | + <FontAwesomeIcon |
| 54 | + color={focused ? colors.primary : colors.foreground3} |
| 55 | + icon={faCircle} |
| 56 | + /> |
| 57 | + ), |
| 58 | + tabBarLabel: ({ focused }) => ( |
| 59 | + <Text style={focused ? styles.focusedLabel : styles.label}>Screen 1</Text> |
| 60 | + ) |
| 61 | +}; |
| 62 | + |
| 63 | +function Tabs() { |
| 64 | + return ( |
| 65 | + <Tab.Navigator |
| 66 | + screenOptions={{ |
| 67 | + tabBarStyle: { |
| 68 | + shadowColor: 'transparent' |
| 69 | + } |
| 70 | + }}> |
| 71 | + <Tab.Screen component={Screen1} name='Screen1' options={tabBarOptions} /> |
| 72 | + <Tab.Screen component={Screen2} name='Screen2' options={tabBarOptions} /> |
| 73 | + </Tab.Navigator> |
| 74 | + ); |
| 75 | +} |
| 76 | + |
| 77 | +export default function BottomTabsNavigatorExample() { |
| 78 | + return ( |
| 79 | + <Screen style={styles.container} includeNavBarHeight> |
| 80 | + <Tabs /> |
| 81 | + </Screen> |
| 82 | + ); |
| 83 | +} |
| 84 | + |
| 85 | +const styles = StyleSheet.create({ |
| 86 | + container: { |
| 87 | + backgroundColor: colors.white |
| 88 | + }, |
| 89 | + focusedLabel: { |
| 90 | + ...text.label3, |
| 91 | + color: colors.primary |
| 92 | + }, |
| 93 | + label: { |
| 94 | + ...text.label3, |
| 95 | + color: colors.foreground3, |
| 96 | + fontWeight: 'normal' |
| 97 | + }, |
| 98 | + screenTitle: { |
| 99 | + ...text.label1, |
| 100 | + color: colors.foreground1, |
| 101 | + marginBottom: spacing.md |
| 102 | + }, |
| 103 | + scrollContainer: { |
| 104 | + padding: spacing.md |
| 105 | + } |
| 106 | +}); |
0 commit comments