Skip to content

Commit 58f34a5

Browse files
committed
Add sortable flex bottom tabs navigator example
1 parent f3f1f0d commit 58f34a5

4 files changed

Lines changed: 122 additions & 4 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
});
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { default as ComplexLayoutExample } from './ComplexLayoutExample';
1+
import BottomTabsNavigatorExample from './BottomTabsNavigatorExample';
2+
import ComplexLayoutExample from './ComplexLayoutExample';
3+
4+
export { BottomTabsNavigatorExample, ComplexLayoutExample };

example/app/src/examples/SortableGrid/tests/BottomTabsNavigatorExample.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Grid({ data }: GridProps) {
4242
function Screen1() {
4343
return (
4444
<ScrollScreen contentContainerStyle={styles.scrollContainer}>
45-
<Text style={styles.screenTitle}>Screen 1</Text>
45+
<Text style={styles.screenTitle}>Screen 1 grid:</Text>
4646
<Grid data={DATA.slice(0, DATA_LENGTH / 2)} />
4747
</ScrollScreen>
4848
);
@@ -51,7 +51,7 @@ function Screen1() {
5151
function Screen2() {
5252
return (
5353
<ScrollScreen contentContainerStyle={styles.scrollContainer}>
54-
<Text style={styles.screenTitle}>Screen 2</Text>
54+
<Text style={styles.screenTitle}>Screen 2 grid:</Text>
5555
<Grid data={DATA.slice(DATA_LENGTH / 2)} />
5656
</ScrollScreen>
5757
);
@@ -70,7 +70,12 @@ const tabBarOptions: BottomTabNavigationOptions = {
7070
};
7171
function Tabs() {
7272
return (
73-
<Tab.Navigator>
73+
<Tab.Navigator
74+
screenOptions={{
75+
tabBarStyle: {
76+
shadowColor: 'transparent'
77+
}
78+
}}>
7479
<Tab.Screen component={Screen1} name='Screen1' options={tabBarOptions} />
7580
<Tab.Screen component={Screen2} name='Screen2' options={tabBarOptions} />
7681
</Tab.Navigator>

example/app/src/examples/navigation/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ const routes: Routes = {
143143
ComplexLayout: {
144144
Component: SortableFlex.tests.ComplexLayoutExample,
145145
name: 'Complex Layout'
146+
},
147+
BottomTabsNavigator: {
148+
Component: SortableFlex.tests.BottomTabsNavigatorExample,
149+
name: 'Bottom Tabs Navigator'
146150
}
147151
}
148152
}

0 commit comments

Comments
 (0)