added support for icons in front of the names

This commit is contained in:
Clément Le Bihan
2023-03-30 23:40:43 +02:00
parent 8d665175fd
commit 5ada22d267
2 changed files with 53 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
import * as React from "react";
import { StyleProp, ViewStyle, StyleSheet } from "react-native";
import { View, Text, Pressable, Box, Row } from "native-base";
import { View, Text, Pressable, Box, Row, Icon } from "native-base";
import {
createNavigatorFactory,
DefaultNavigatorOptions,
@@ -22,6 +22,8 @@ type TabNavigationConfig = {
// Supported screen options
type TabNavigationOptions = {
title?: string;
iconProvider?: any;
iconName?: string;
};
// Map of event name and the type of data (in event.data)
@@ -69,7 +71,15 @@ function TabNavigator({
<NavigationContent>
<Row height={"900px"}>
<View
style={[{ flexDirection: "column", width: "300px" }, tabBarStyle]}
style={[
{
display: "flex",
flexDirection: "column",
justifyContent: "flex-start",
width: "300px",
},
tabBarStyle,
]}
>
{state.routes.map((route) => (
<Pressable
@@ -81,7 +91,7 @@ function TabNavigator({
canPreventDefault: true,
data: {
isAlreadyFocused:
route.key === state.routes[state.index].key,
route.key === state.routes[state.index]?.key,
},
});
@@ -95,27 +105,44 @@ function TabNavigator({
style={{ flex: 1 }}
>
{({ isHovered, isPressed }) => (
<Box bgColor={(() => {
let colorLevel = 0;
if (isHovered) {
colorLevel += 100;
}
if (route.key === state.routes[state.index].key) {
colorLevel += 300;
}
if (isPressed) {
colorLevel += 200;
}
<Box
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
flexDirection: "row",
}}
bgColor={(() => {
let colorLevel = 0;
if (isHovered) {
colorLevel += 100;
}
if (route.key === state.routes[state.index]?.key) {
colorLevel += 300;
}
if (isPressed) {
colorLevel += 200;
}
if (colorLevel <= 0) {
return "transparent";
}
return `primary.${colorLevel}`;
})()}>
<Text>
{descriptors[route.key].options.title || route.name}
</Text>
</Box>
if (colorLevel <= 0) {
return "transparent";
}
return `primary.${colorLevel}`;
})()}
>
{descriptors[route.key]?.options.iconProvider &&
descriptors[route.key]?.options.iconName && (
<Icon
as={descriptors[route.key]?.options.iconProvider}
name={descriptors[route.key]?.options.iconName}
size="lg"
color="white"
/>
)}
<Text>
{descriptors[route.key]?.options.title || route.name}
</Text>
</Box>
)}
</Pressable>
))}
@@ -127,7 +154,7 @@ function TabNavigator({
key={route.key}
style={[{ display: i === state.index ? "flex" : "none" }]}
>
{descriptors[route.key].render()}
{descriptors[route.key]?.render()}
</View>
);
})}

View File

@@ -10,6 +10,7 @@ import { SettingsState, updateSettings } from '../state/SettingsSlice';
import { AvailableLanguages, translate, Translate } from "../i18n/i18n";
import TextButton from '../components/TextButton';
import createTabRowNavigator from '../components/navigators/TabRowNavigator';
import { FontAwesome } from '@expo/vector-icons';
import API from '../API';
@@ -258,7 +259,7 @@ const TabRow = createTabRowNavigator();
const SetttingsNavigator = () => {
return (
<TabRow.Navigator initialRouteName='Main'>
<TabRow.Screen name='Main' component={MainView} />
<TabRow.Screen name='Main' component={MainView} options={{ title: "Profil", iconProvider: FontAwesome, iconName: "user" }} />
<TabRow.Screen name='Preferences' component={PreferencesView} />
<TabRow.Screen name='Notifications' component={NotificationsView} />
<TabRow.Screen name='Privacy' component={PrivacyView} />