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
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "Scale Manager",
"slug": "scaleManager",
"version": "1.2.7",
"version": "1.2.8",
"orientation": "portrait",
"icon": "./assets/images/noBgScaleManagerLogo.png",
"scheme": "myapp",
Expand Down
138 changes: 78 additions & 60 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
import { Tabs } from "expo-router";
import { TopTabs } from "expo-router/js-top-tabs";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { getServerConfig } from "../utils/getServer";
import { useEffect, useState } from "react";
import { useEffect, useState, type ComponentProps } from "react";
import { StyleSheet, Text, type ColorValue } from "react-native";
import { isV026OrHigher } from "../utils/headscaleVersion";
import { useTheme } from "@/theme";
import { spacing } from "@/theme/spacing";

function tabIcon(name: ComponentProps<typeof MaterialCommunityIcons>["name"]) {
return ({ color }: { color: string }) => (
<MaterialCommunityIcons name={name} color={color} size={24} />
);
}

function TabLabel({
color,
children,
}: {
color: ColorValue;
children: string;
}) {
const { theme } = useTheme();

return (
<Text
numberOfLines={1}
style={{
...theme.typography.label,
marginTop: 2,
fontSize: 11,
color,
textAlign: "center",
}}
>
{children}
</Text>
);
}

export default function TabLayout() {
const [hideRoutes, setHideRoutes] = useState(false);
const { theme } = useTheme();
Expand All @@ -21,113 +53,99 @@ export default function TabLayout() {
}, []);

return (
<Tabs
<TopTabs
tabBarPosition="bottom"
screenOptions={{
headerShown: false,
swipeEnabled: true,
animationEnabled: true,
lazy: true,
lazyPreloadDistance: 1,
tabBarShowIcon: true,
tabBarActiveTintColor: theme.colors.primary,
tabBarInactiveTintColor: theme.colors.tabBarInactive,
tabBarPressColor: theme.colors.primarySoft,
tabBarIndicatorStyle: { height: 0 },
tabBarStyle: {
backgroundColor: theme.colors.tabBar,
borderTopColor: theme.colors.tabBarBorder,
borderTopWidth: 1,
height: 74,
borderTopWidth: StyleSheet.hairlineWidth,
height: 84,
paddingTop: spacing.xs,
paddingBottom: spacing.sm,
},
tabBarLabelStyle: {
...theme.typography.label,
marginTop: 2,
elevation: 0,
shadowOpacity: 0,
},
tabBarItemStyle: {
paddingVertical: spacing.xs,
paddingHorizontal: 0,
},
tabBarLabel: ({
color,
children,
}: {
color: ColorValue;
children: string;
}) => <TabLabel color={color}>{children}</TabLabel>,
sceneStyle: { backgroundColor: theme.colors.background },
}}
>
<Tabs.Screen
<TopTabs.Screen
name="index"
options={{
title: "Home",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={24} />
),
tabBarIcon: tabIcon("home"),
}}
/>

<Tabs.Screen
<TopTabs.Screen
name="users"
options={{
title: "Users",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account-group" color={color} size={24} />
),
tabBarIcon: tabIcon("account-group"),
}}
/>

<Tabs.Screen
<TopTabs.Screen
name="devices"
options={{
title: "Devices",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="devices" color={color} size={24} />
),
tabBarIcon: tabIcon("devices"),
}}
/>

<Tabs.Screen
<TopTabs.Screen
name="preauthkeys"
options={{
title: "Auth Keys",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="key-chain" color={color} size={24} />
),
tabBarIcon: tabIcon("key-chain"),
}}
/>

<Tabs.Screen
<TopTabs.Screen
name="apikeys"
options={{
title: "API Keys",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="key" color={color} size={24} />
),
tabBarIcon: tabIcon("key"),
}}
/>

<Tabs.Screen
name="routes"
options={{
title: "Routes",
headerShown: false,
href: hideRoutes ? null : "/routes",
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons
name="router-network"
color={color}
size={24}
/>
),
}}
/>
<TopTabs.Protected guard={!hideRoutes}>
<TopTabs.Screen
name="routes"
options={{
title: "Routes",
tabBarIcon: tabIcon("router-network"),
}}
/>
</TopTabs.Protected>

<Tabs.Screen
<TopTabs.Screen
name="acl"
options={{
title: "ACL",
headerShown: false,
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons
name="shield-account"
color={color}
size={24}
/>
),
tabBarIcon: tabIcon("shield-account"),
}}
/>
</Tabs>
</TopTabs>
);
}
Loading
Loading