245 lines
8.7 KiB
TypeScript
245 lines
8.7 KiB
TypeScript
import { useTabletLayout } from "@/hooks/use-tablet-layout"
|
|
import { TabletMiniPlayer } from "@/components/tablet-mini-player"
|
|
import { TabletPlayerLayoutProvider } from "@/contexts/tablet-player-layout"
|
|
import Animated from "react-native-reanimated"
|
|
import { NavigationBar } from "expo-navigation-bar"
|
|
import {
|
|
ScreenPaletteProvider,
|
|
useAndroidTabPalette,
|
|
useAndroidTabHasArtworkPalette,
|
|
useTabletBackgroundStyle,
|
|
} from "@/contexts/android-tab-theme"
|
|
import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router"
|
|
import { NativeTabs } from "expo-router/native-tabs"
|
|
import { DynamicColorIOS, Platform } from "react-native"
|
|
import { useMemo } from "react"
|
|
|
|
import { AndroidMiniPlayer, TabBottomAccessory } from "@/components/mini-player"
|
|
import { useAndroidKeyboardVisible } from "@/hooks/use-android-keyboard-visible"
|
|
import { usePlaybackQueue } from "@/contexts/playback"
|
|
import { appleMusic, colors, miniPlayerHeight, useIsDark } from "@/lib/theme"
|
|
|
|
export const unstable_settings = { anchor: "library" }
|
|
|
|
function useRouterTheme() {
|
|
const themeIsDark = useIsDark()
|
|
const androidPalette = useAndroidTabPalette()
|
|
const isDark = Platform.OS === "android" ? androidPalette.isDark : themeIsDark
|
|
|
|
return useMemo(() => {
|
|
const palette = isDark ? colors.dark : colors.light
|
|
const android = Platform.OS === "android" ? androidPalette : null
|
|
const base = isDark ? DarkTheme : DefaultTheme
|
|
|
|
return {
|
|
...base,
|
|
colors: {
|
|
...base.colors,
|
|
background: android?.background ?? palette.background,
|
|
card: android?.surface ?? palette.card,
|
|
text: android?.foreground ?? palette.foreground,
|
|
border: android?.divider ?? palette.border,
|
|
primary: android?.accentText ?? palette.primary,
|
|
},
|
|
}
|
|
}, [isDark, androidPalette])
|
|
}
|
|
|
|
function useNativeTabColors() {
|
|
const themeIsDark = useIsDark()
|
|
const androidPalette = useAndroidTabPalette()
|
|
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
|
|
const selectedColor = hasArtworkPalette
|
|
? androidPalette.foreground
|
|
: androidPalette.accentText
|
|
const isDark = Platform.OS === "android" ? androidPalette.isDark : themeIsDark
|
|
const inactive = appleMusic.tabInactive
|
|
|
|
const iconColor =
|
|
Platform.OS === "ios"
|
|
? {
|
|
default: DynamicColorIOS({ dark: inactive, light: "#636366" }),
|
|
selected: appleMusic.pink,
|
|
}
|
|
: {
|
|
default: androidPalette.secondaryForeground,
|
|
selected: selectedColor,
|
|
}
|
|
|
|
const labelColor =
|
|
Platform.OS === "ios"
|
|
? DynamicColorIOS({ dark: inactive, light: "#636366" })
|
|
: androidPalette.secondaryForeground
|
|
|
|
return {
|
|
isDark,
|
|
tintColor: Platform.OS === "android" ? selectedColor : appleMusic.pink,
|
|
iconColor,
|
|
labelStyle: {
|
|
default: { color: labelColor, fontSize: 10 },
|
|
selected: {
|
|
color: Platform.OS === "android" ? selectedColor : appleMusic.pink,
|
|
fontSize: 10,
|
|
fontWeight: "600" as const,
|
|
},
|
|
},
|
|
blurEffect: isDark
|
|
? "systemChromeMaterialDark"
|
|
: "systemChromeMaterialLight",
|
|
backgroundColor:
|
|
Platform.OS === "ios" ? undefined : androidPalette.background,
|
|
}
|
|
}
|
|
|
|
function TabsContent() {
|
|
const tabletLayout = useTabletLayout()
|
|
const keyboardVisible = useAndroidKeyboardVisible()
|
|
const routerTheme = useRouterTheme()
|
|
const tabColors = useNativeTabColors()
|
|
const backgroundStyle = useTabletBackgroundStyle()
|
|
const { currentSong, queueSongIds } = usePlaybackQueue()
|
|
const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0)
|
|
|
|
// NativeTabs already owns the tab bar and system navigation insets.
|
|
const androidContentStyle =
|
|
Platform.OS === "android"
|
|
? {
|
|
paddingBottom:
|
|
showBottomAccessory && !keyboardVisible ? miniPlayerHeight : 0,
|
|
}
|
|
: undefined
|
|
|
|
return (
|
|
<ThemeProvider value={routerTheme}>
|
|
<Animated.View style={[{ flex: 1 }, backgroundStyle]}>
|
|
{Platform.OS === "android" ? (
|
|
<NavigationBar style={tabColors.isDark ? "light" : "dark"} />
|
|
) : null}
|
|
<NativeTabs
|
|
sidebarAdaptable
|
|
blurEffect={
|
|
tabColors.blurEffect as
|
|
"systemChromeMaterialDark" | "systemChromeMaterialLight"
|
|
}
|
|
backgroundColor={tabColors.backgroundColor}
|
|
iconColor={tabColors.iconColor}
|
|
labelStyle={tabColors.labelStyle}
|
|
tintColor={tabColors.tintColor}
|
|
minimizeBehavior="onScrollDown"
|
|
{...(Platform.OS === "android"
|
|
? // A new ripple color rebuilds Material's item backgrounds and
|
|
// cuts off the in-flight ripple, so it must not follow the palette.
|
|
{ disableIndicator: true, rippleColor: appleMusic.tabInactive }
|
|
: {})}
|
|
>
|
|
{Platform.OS === "ios" && !tabletLayout && showBottomAccessory ? (
|
|
<NativeTabs.BottomAccessory>
|
|
<TabBottomAccessory />
|
|
</NativeTabs.BottomAccessory>
|
|
) : null}
|
|
|
|
<NativeTabs.Trigger
|
|
name="home"
|
|
disableTransparentOnScrollEdge
|
|
contentStyle={androidContentStyle}
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="house.fill" md="home" />
|
|
<NativeTabs.Trigger.Label>Home</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
|
|
<NativeTabs.Trigger
|
|
name="library"
|
|
disableTransparentOnScrollEdge
|
|
contentStyle={androidContentStyle}
|
|
>
|
|
<NativeTabs.Trigger.Icon
|
|
sf="music.note.square.stack.fill"
|
|
md="library_music"
|
|
/>
|
|
<NativeTabs.Trigger.Label>
|
|
{tabletLayout ? "Recently Added" : "Library"}
|
|
</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
|
|
<NativeTabs.Trigger
|
|
name="search"
|
|
disableTransparentOnScrollEdge
|
|
contentStyle={androidContentStyle}
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="magnifyingglass" md="search" />
|
|
<NativeTabs.Trigger.Label>Search</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(albums)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="square.stack" />
|
|
<NativeTabs.Trigger.Label>Albums</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(artists)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="mic" />
|
|
<NativeTabs.Trigger.Label>Artists</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(songs)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="music.note" />
|
|
<NativeTabs.Trigger.Label>Songs</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(playlists)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="music.note.list" />
|
|
<NativeTabs.Trigger.Label>All Playlists</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(favorites)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="star" />
|
|
<NativeTabs.Trigger.Label>Favorites</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(recent)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="clock" />
|
|
<NativeTabs.Trigger.Label>Recently Played</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
<NativeTabs.Trigger
|
|
name="(downloads)"
|
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
disableTransparentOnScrollEdge
|
|
>
|
|
<NativeTabs.Trigger.Icon sf="arrow.down.circle" />
|
|
<NativeTabs.Trigger.Label>Downloads</NativeTabs.Trigger.Label>
|
|
</NativeTabs.Trigger>
|
|
</NativeTabs>
|
|
{!keyboardVisible ? <AndroidMiniPlayer /> : null}
|
|
{tabletLayout ? <TabletMiniPlayer /> : null}
|
|
</Animated.View>
|
|
</ThemeProvider>
|
|
)
|
|
}
|
|
|
|
export default function TabsLayout() {
|
|
return (
|
|
<ScreenPaletteProvider>
|
|
<TabletPlayerLayoutProvider>
|
|
<TabsContent />
|
|
</TabletPlayerLayoutProvider>
|
|
</ScreenPaletteProvider>
|
|
)
|
|
}
|