Files
otunes/apps/mobile/app/(app)/(tabs)/_layout.tsx
T
joshuafhiggins 9da758b196 perf: optimize app rendering and data loading (#18)
- Virtualize mobile lists and defer queue loading
- Split playback state from actions to reduce rerenders
- Skip invalid or unnecessary Convex queries

Reviewed-on: #18
2026-09-05 16:35:37 -04:00

122 lines
3.5 KiB
TypeScript

import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router"
import { NativeTabs } from "expo-router/unstable-native-tabs"
import { DynamicColorIOS, Platform, useColorScheme } from "react-native"
import { useMemo } from "react"
import { TabBottomAccessory } from "@/components/mini-player"
import { usePlaybackQueue } from "@/contexts/playback"
import { appleMusic, colors } from "@/lib/theme"
function useRouterTheme() {
const isDark = useColorScheme() === "dark"
return useMemo(() => {
const palette = isDark ? colors.dark : colors.light
const base = isDark ? DarkTheme : DefaultTheme
return {
...base,
colors: {
...base.colors,
background: palette.background,
card: palette.card,
text: palette.foreground,
border: palette.border,
primary: palette.primary,
},
}
}, [isDark])
}
function useNativeTabColors() {
const isDark = useColorScheme() === "dark"
const inactive = appleMusic.tabInactive
const iconColor =
Platform.OS === "ios"
? {
default: DynamicColorIOS({ dark: inactive, light: "#636366" }),
selected: appleMusic.pink,
}
: {
default: isDark ? inactive : "#636366",
selected: appleMusic.pink,
}
const labelColor =
Platform.OS === "ios"
? DynamicColorIOS({ dark: inactive, light: "#636366" })
: isDark
? inactive
: "#636366"
return {
isDark,
iconColor,
labelStyle: {
default: { color: labelColor, fontSize: 10 },
selected: {
color: appleMusic.pink,
fontSize: 10,
fontWeight: "600" as const,
},
},
blurEffect: isDark
? "systemChromeMaterialDark"
: "systemChromeMaterialLight",
backgroundColor:
Platform.OS === "ios"
? undefined
: isDark
? appleMusic.background
: colors.light.background,
}
}
export default function TabsLayout() {
const routerTheme = useRouterTheme()
const tabColors = useNativeTabColors()
const { currentSong, queueSongIds } = usePlaybackQueue()
const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0)
return (
<ThemeProvider value={routerTheme}>
<NativeTabs
blurEffect={
tabColors.blurEffect as
"systemChromeMaterialDark" | "systemChromeMaterialLight"
}
backgroundColor={tabColors.backgroundColor}
iconColor={tabColors.iconColor}
labelStyle={tabColors.labelStyle}
tintColor={appleMusic.pink}
minimizeBehavior="onScrollDown"
>
{showBottomAccessory ? (
<NativeTabs.BottomAccessory>
<TabBottomAccessory />
</NativeTabs.BottomAccessory>
) : null}
<NativeTabs.Trigger name="home" disableTransparentOnScrollEdge>
<NativeTabs.Trigger.Icon sf="house.fill" md="home" />
<NativeTabs.Trigger.Label>Home</NativeTabs.Trigger.Label>
</NativeTabs.Trigger>
<NativeTabs.Trigger name="library" disableTransparentOnScrollEdge>
<NativeTabs.Trigger.Icon
sf="music.note.square.stack.fill"
md="library_music"
/>
<NativeTabs.Trigger.Label>Library</NativeTabs.Trigger.Label>
</NativeTabs.Trigger>
<NativeTabs.Trigger name="search" disableTransparentOnScrollEdge>
<NativeTabs.Trigger.Icon sf="magnifyingglass" md="search" />
<NativeTabs.Trigger.Label>Search</NativeTabs.Trigger.Label>
</NativeTabs.Trigger>
</NativeTabs>
</ThemeProvider>
)
}