Compare commits

...
21 changed files with 427 additions and 115 deletions

No files matched your search

@@ -1,7 +1,11 @@
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { renderTabScreenContent } from "@/components/tab-screen-content" import { renderTabScreenContent } from "@/components/tab-screen-content"
import { useStackScreenOptions, tabStackScreenTitles } from "@/lib/navigation" import {
inlineTitleOptions,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation" import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
export default function TabletSectionLayout({ segment }: { segment: string }) { export default function TabletSectionLayout({ segment }: { segment: string }) {
@@ -14,6 +18,7 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
screenLayout={renderTabScreenContent} screenLayout={renderTabScreenContent}
screenOptions={({ route }) => ({ screenOptions={({ route }) => ({
...options, ...options,
...inlineTitleOptions,
title: title:
route.name === "index" route.name === "index"
? section?.title ? section?.title
+11 -13
View File
@@ -2,7 +2,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
export const unstable_settings = { export const unstable_settings = {
anchor: "index", anchor: "index",
@@ -16,19 +21,12 @@ export default function HomeLayout() {
screenLayout={renderTabScreenContent} screenLayout={renderTabScreenContent}
screenOptions={({ route }) => ({ screenOptions={({ route }) => ({
...baseOptions, ...baseOptions,
...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Home", title: tabStackScreenTitles[route.name] ?? "Home",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
@@ -53,7 +53,7 @@ export default function AlbumsScreen() {
return ( return (
<> <>
{searchBar} {searchBar}
<MediaGridSkeleton /> <MediaGridSkeleton title="Albums" />
</> </>
) )
} }
@@ -63,6 +63,7 @@ export default function AlbumsScreen() {
{searchBar} {searchBar}
<MediaGridList <MediaGridList
title="Albums"
content={albums} content={albums}
paddingBottom={contentBottomInset} paddingBottom={contentBottomInset}
onEndReached={() => { onEndReached={() => {
@@ -2,12 +2,13 @@ import { Ionicons } from "@expo/vector-icons"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { memo, useCallback } from "react" import { memo, useCallback } from "react"
import { import {
FlatList, type FlatList,
Pressable, Pressable,
StyleSheet, StyleSheet,
Text, Text,
type ListRenderItemInfo, type ListRenderItemInfo,
} from "react-native" } from "react-native"
import Animated from "react-native-reanimated"
import { import {
MediaContextMenu, MediaContextMenu,
@@ -15,6 +16,7 @@ import {
} from "@/components/media-context-menu" } from "@/components/media-context-menu"
import { CoverImage } from "@/components/cover-image" import { CoverImage } from "@/components/cover-image"
import { ArtistListSkeleton } from "@/components/skeletons" import { ArtistListSkeleton } from "@/components/skeletons"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { contentBottomInset } from "@/components/player" import { contentBottomInset } from "@/components/player"
import { useServerConfig } from "@/contexts/server-config" import { useServerConfig } from "@/contexts/server-config"
import { import {
@@ -33,6 +35,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
const PAGE_SIZE = 50 const PAGE_SIZE = 50
export default function ArtistsScreen() { export default function ArtistsScreen() {
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseArtist>>()
const { push } = useAppNavigation() const { push } = useAppNavigation()
const colors = useThemeColors() const colors = useThemeColors()
const { config } = useServerConfig() const { config } = useServerConfig()
@@ -94,7 +97,7 @@ export default function ArtistsScreen() {
return ( return (
<> <>
{searchBar} {searchBar}
<ArtistListSkeleton /> <ArtistListSkeleton title="Artists" />
</> </>
) )
} }
@@ -103,8 +106,11 @@ export default function ArtistsScreen() {
<> <>
{searchBar} {searchBar}
<FlatList <Animated.FlatList
{...longListProps} {...longListProps}
ref={ref}
scrollEventThrottle={16}
ListHeaderComponent={<ScreenTitle title="Artists" scrollY={scrollY} />}
data={artists} data={artists}
keyExtractor={artistKey} keyExtractor={artistKey}
renderItem={renderItem} renderItem={renderItem}
@@ -1,3 +1,4 @@
import { useContext } from "react"
import { Pressable } from "react-native" import { Pressable } from "react-native"
import { MediaGridList } from "@/components/media-cards" import { MediaGridList } from "@/components/media-cards"
@@ -10,19 +11,20 @@ import { Ionicons } from "@expo/vector-icons"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { SymbolView } from "expo-symbols" import { SymbolView } from "expo-symbols"
import { useAddToPlaylist } from "@/contexts/add-to-playlist" import { useAddToPlaylist } from "@/contexts/add-to-playlist"
import { TabletSectionContext } from "@/lib/tablet-navigation"
export default function PlaylistsTabScreen() { export default function PlaylistsTabScreen() {
const colors = useThemeColors() const colors = useThemeColors()
const playlists = useCachedQuery(api.playlists.listAllPlaylists) const playlists = useCachedQuery(api.playlists.listAllPlaylists)
const { openCreatePlaylist } = useAddToPlaylist() const { openCreatePlaylist } = useAddToPlaylist()
const title = useContext(TabletSectionContext)?.title ?? "Playlists"
if (playlists === undefined) { if (playlists === undefined) {
return ( return (
<> <>
<Stack.Screen <Stack.Screen
options={{ options={{
title: "Playlists", title,
headerLargeTitle: true,
headerRight: () => ( headerRight: () => (
<Pressable <Pressable
onPress={openCreatePlaylist} onPress={openCreatePlaylist}
@@ -38,7 +40,7 @@ export default function PlaylistsTabScreen() {
), ),
}} }}
/> />
<MediaGridSkeleton /> <MediaGridSkeleton title={title} />
</> </>
) )
} }
@@ -47,8 +49,7 @@ export default function PlaylistsTabScreen() {
<> <>
<Stack.Screen <Stack.Screen
options={{ options={{
title: "Playlists", title,
headerLargeTitle: true,
headerRight: () => ( headerRight: () => (
<Pressable <Pressable
onPress={openCreatePlaylist} onPress={openCreatePlaylist}
@@ -61,6 +62,7 @@ export default function PlaylistsTabScreen() {
}} }}
/> />
<MediaGridList <MediaGridList
title={title}
content={playlists} content={playlists}
paddingBottom={tabContentBottomInset} paddingBottom={tabContentBottomInset}
/> />
@@ -1,10 +1,16 @@
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { useCallback, useState } from "react" import { useCallback, useState } from "react"
import { FlatList, StyleSheet, type ListRenderItemInfo } from "react-native" import {
type FlatList,
StyleSheet,
type ListRenderItemInfo,
} from "react-native"
import Animated from "react-native-reanimated"
import type { MediaAction } from "@/components/media-context-menu" import type { MediaAction } from "@/components/media-context-menu"
import { contentBottomInset, SongListRow } from "@/components/player" import { contentBottomInset, SongListRow } from "@/components/player"
import { SongListSkeleton } from "@/components/skeletons" import { SongListSkeleton } from "@/components/skeletons"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { useFavorites } from "@/contexts/favorites" import { useFavorites } from "@/contexts/favorites"
import { usePlaybackActions } from "@/contexts/playback" import { usePlaybackActions } from "@/contexts/playback"
import { import {
@@ -20,6 +26,7 @@ import { longListProps } from "@/lib/list"
const PAGE_SIZE = 50 const PAGE_SIZE = 50
export default function SongsScreen() { export default function SongsScreen() {
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
const { playFromLibrarySong } = usePlaybackActions() const { playFromLibrarySong } = usePlaybackActions()
const { isSongFavorite } = useFavorites() const { isSongFavorite } = useFavorites()
const { handleSongAction } = useMediaMenuActions() const { handleSongAction } = useMediaMenuActions()
@@ -87,7 +94,7 @@ export default function SongsScreen() {
return ( return (
<> <>
{searchBar} {searchBar}
<SongListSkeleton /> <SongListSkeleton title="Songs" />
</> </>
) )
} }
@@ -96,8 +103,11 @@ export default function SongsScreen() {
<> <>
{searchBar} {searchBar}
<FlatList <Animated.FlatList
{...longListProps} {...longListProps}
ref={ref}
scrollEventThrottle={16}
ListHeaderComponent={<ScreenTitle title="Songs" scrollY={scrollY} />}
data={songs} data={songs}
keyExtractor={songKey} keyExtractor={songKey}
renderItem={renderItem} renderItem={renderItem}
@@ -1,6 +1,6 @@
import { useMemo } from "react" import { useMemo } from "react"
import { import {
FlatList, type FlatList,
Pressable, Pressable,
StyleSheet, StyleSheet,
Text, Text,
@@ -8,8 +8,10 @@ import {
type ListRenderItemInfo, type ListRenderItemInfo,
} from "react-native" } from "react-native"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import Animated from "react-native-reanimated"
import { CoverImage } from "@/components/cover-image" import { CoverImage } from "@/components/cover-image"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { import {
FAVORITES_DOWNLOAD_ID, FAVORITES_DOWNLOAD_ID,
@@ -53,6 +55,7 @@ export default function DownloadsScreen() {
const { push } = useAppNavigation() const { push } = useAppNavigation()
const { columns, cardWidth, onLayout, horizontalPadding, gap } = const { columns, cardWidth, onLayout, horizontalPadding, gap } =
useMediaGridLayout() useMediaGridLayout()
const { ref, scrollY } = useScreenTitleScroll<FlatList<Card>>()
const cards = useMemo<Card[]>(() => { const cards = useMemo<Card[]>(() => {
if (!queue) return [] if (!queue) return []
@@ -135,8 +138,10 @@ export default function DownloadsScreen() {
return ( return (
<> <>
<Stack.Screen options={{ title: "Downloads", headerLargeTitle: true }} /> <Stack.Screen options={{ title: "Downloads" }} />
<FlatList <Animated.FlatList
ref={ref}
scrollEventThrottle={16}
key={columns} key={columns}
onLayout={onLayout} onLayout={onLayout}
data={cards} data={cards}
@@ -149,13 +154,20 @@ export default function DownloadsScreen() {
numColumns={columns} numColumns={columns}
style={{ flex: 1, backgroundColor: colors.background }} style={{ flex: 1, backgroundColor: colors.background }}
contentContainerStyle={{ contentContainerStyle={{
paddingTop: spacing.lg,
paddingHorizontal: horizontalPadding, paddingHorizontal: horizontalPadding,
paddingBottom: tabContentBottomInset, paddingBottom: tabContentBottomInset,
gap, gap,
}} }}
columnWrapperStyle={columns > 1 ? { gap } : undefined} columnWrapperStyle={columns > 1 ? { gap } : undefined}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
ListHeaderComponent={
<ScreenTitle
title="Downloads"
scrollY={scrollY}
// The list padding already insets the title.
style={{ paddingHorizontal: 0 }}
/>
}
ListEmptyComponent={ ListEmptyComponent={
<View style={styles.empty}> <View style={styles.empty}>
<Text style={{ color: colors.mutedForeground }}> <Text style={{ color: colors.mutedForeground }}>
@@ -1,15 +1,17 @@
import { useCallback, useMemo } from "react" import { useCallback, useMemo } from "react"
import { import {
FlatList, type FlatList,
Pressable, Pressable,
StyleSheet, StyleSheet,
Text, Text,
View, View,
type ListRenderItemInfo, type ListRenderItemInfo,
} from "react-native" } from "react-native"
import Animated from "react-native-reanimated"
import { Ionicons } from "@expo/vector-icons" import { Ionicons } from "@expo/vector-icons"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row" import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
import type { MediaAction } from "@/components/media-context-menu" import type { MediaAction } from "@/components/media-context-menu"
import { contentBottomInset, SongListRow } from "@/components/player" import { contentBottomInset, SongListRow } from "@/components/player"
@@ -52,6 +54,7 @@ export default function OtherDownloadsScreen() {
const { isSongFavorite } = useFavorites() const { isSongFavorite } = useFavorites()
const { handleSongAction } = useMediaMenuActions() const { handleSongAction } = useMediaMenuActions()
const swipeGroup = useSwipeRowGroup() const swipeGroup = useSwipeRowGroup()
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
const handlePlaySong = useCallback( const handlePlaySong = useCallback(
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN), (song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
@@ -90,11 +93,11 @@ export default function OtherDownloadsScreen() {
return ( return (
<> <>
<Stack.Screen <Stack.Screen options={{ title: OTHER_DOWNLOADS_TITLE }} />
options={{ title: OTHER_DOWNLOADS_TITLE, headerLargeTitle: false }} <Animated.FlatList
/>
<FlatList
{...longListProps} {...longListProps}
ref={ref}
scrollEventThrottle={16}
data={songs} data={songs}
keyExtractor={(song) => song.id} keyExtractor={(song) => song.id}
renderItem={renderItem} renderItem={renderItem}
@@ -103,25 +106,32 @@ export default function OtherDownloadsScreen() {
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
onScrollBeginDrag={swipeGroup.closeOpenRow} onScrollBeginDrag={swipeGroup.closeOpenRow}
ListHeaderComponent={ ListHeaderComponent={
songs.length > 0 ? ( <>
<View style={styles.actions}> <ScreenTitle title={OTHER_DOWNLOADS_TITLE} scrollY={scrollY} />
<Button {songs.length > 0 ? (
title="Play" <View style={styles.actions}>
icon="play" <Button
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)} title="Play"
style={styles.play} icon="play"
/> onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
<Pressable style={styles.play}
accessibilityRole="button" />
accessibilityLabel="Shuffle" <Pressable
hitSlop={8} accessibilityRole="button"
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)} accessibilityLabel="Shuffle"
style={[styles.shuffle, { backgroundColor: colors.card }]} hitSlop={8}
> onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
<Ionicons name="shuffle" size={24} color={colors.foreground} /> style={[styles.shuffle, { backgroundColor: colors.card }]}
</Pressable> >
</View> <Ionicons
) : undefined name="shuffle"
size={24}
color={colors.foreground}
/>
</Pressable>
</View>
) : null}
</>
} }
ListEmptyComponent={ ListEmptyComponent={
<Text style={[styles.empty, { color: colors.mutedForeground }]}> <Text style={[styles.empty, { color: colors.mutedForeground }]}>
+24 -4
View File
@@ -1,8 +1,11 @@
import { memo } from "react" import { memo } from "react"
import { ScrollView, StyleSheet } from "react-native" import { type ScrollViewInstance, StyleSheet } from "react-native"
import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards" import { ContentCarousel } from "@/components/media-cards"
import { HomeSkeleton } from "@/components/skeletons" import { HomeSkeleton } from "@/components/skeletons"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query" import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
@@ -38,6 +41,7 @@ const HomeCarousels = memo(function HomeCarousels({
export default function HomeScreen() { export default function HomeScreen() {
const colors = useThemeColors() const colors = useThemeColors()
const { ref, scrollY } = useScreenTitleScroll<ScrollViewInstance>()
const recentlyAdded = useCachedPaginatedQuery( const recentlyAdded = useCachedPaginatedQuery(
api.library.browseRecentlyAddedPaginated, api.library.browseRecentlyAddedPaginated,
{}, {},
@@ -53,14 +57,18 @@ export default function HomeScreen() {
(result) => result.status === "LoadingFirstPage" && !result.isCached (result) => result.status === "LoadingFirstPage" && !result.isCached
) )
if (isLoading) { if (isLoading) {
return <HomeSkeleton /> return (
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
)
} }
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT) const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT) const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
return ( return (
<ScrollView <Animated.ScrollView
ref={ref}
scrollEventThrottle={16}
style={{ flex: 1, backgroundColor: colors.background }} style={{ flex: 1, backgroundColor: colors.background }}
contentContainerStyle={[ contentContainerStyle={[
styles.content, styles.content,
@@ -68,8 +76,14 @@ export default function HomeScreen() {
]} ]}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
> >
<ScreenTitle
title="Home"
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
style={styles.title}
/>
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} /> <HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
</ScrollView> </Animated.ScrollView>
) )
} }
@@ -78,4 +92,10 @@ const styles = StyleSheet.create({
padding: spacing.lg, padding: spacing.lg,
gap: spacing.xl, gap: spacing.xl,
}, },
// The content padding already insets the title.
title: {
paddingHorizontal: 0,
marginTop: -spacing.lg,
marginBottom: -spacing.md,
},
}) })
@@ -14,11 +14,12 @@ export default function RecentlyAddedScreen() {
) )
if (status === "LoadingFirstPage" && !isCached) { if (status === "LoadingFirstPage" && !isCached) {
return <MediaGridSkeleton /> return <MediaGridSkeleton title="Recently Added" />
} }
return ( return (
<MediaGridList <MediaGridList
title="Recently Added"
content={results} content={results}
paddingBottom={contentBottomInset} paddingBottom={contentBottomInset}
onEndReached={() => { onEndReached={() => {
@@ -14,11 +14,12 @@ export default function RecentlyPlayedScreen() {
) )
if (status === "LoadingFirstPage" && !isCached) { if (status === "LoadingFirstPage" && !isCached) {
return <MediaGridSkeleton /> return <MediaGridSkeleton title="Recently Played" />
} }
return ( return (
<MediaGridList <MediaGridList
title="Recently Played"
content={results} content={results}
paddingBottom={contentBottomInset} paddingBottom={contentBottomInset}
onEndReached={() => { onEndReached={() => {
@@ -3,7 +3,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
export const unstable_settings = { export const unstable_settings = {
anchor: "index", anchor: "index",
@@ -18,21 +23,14 @@ export default function LibraryLayout() {
screenLayout={renderTabScreenContent} screenLayout={renderTabScreenContent}
screenOptions={({ route }) => ({ screenOptions={({ route }) => ({
...baseOptions, ...baseOptions,
...inlineTitleOptions,
title: title:
tabStackScreenTitles[route.name] ?? tabStackScreenTitles[route.name] ??
(tabletLayout ? "Recently Added" : "Library"), (tabletLayout ? "Recently Added" : "Library"),
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
+12 -1
View File
@@ -8,6 +8,7 @@ import { Ionicons } from "@expo/vector-icons"
import { MediaGridList } from "@/components/media-cards" import { MediaGridList } from "@/components/media-cards"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { MediaGridSkeleton } from "@/components/skeletons" import { MediaGridSkeleton } from "@/components/skeletons"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query" import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { useAppNavigation } from "@/lib/app-navigation" import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
@@ -72,6 +73,7 @@ export default function LibraryScreen() {
const { push } = useAppNavigation() const { push } = useAppNavigation()
const isTablet = tabletLayout const isTablet = tabletLayout
const colors = useThemeColors() const colors = useThemeColors()
const title = isTablet ? "Recently Added" : "Library"
const { results, status, loadMore, isCached } = useCachedPaginatedQuery( const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
api.library.browseRecentlyAddedPaginated, api.library.browseRecentlyAddedPaginated,
{}, {},
@@ -124,11 +126,20 @@ export default function LibraryScreen() {
) )
if (status === "LoadingFirstPage" && !isCached) { if (status === "LoadingFirstPage" && !isCached) {
return <MediaGridSkeleton contentInset={false} header={listHeader} /> return (
<MediaGridSkeleton
title={title}
titleAccessory={<ProfileHeaderButton />}
contentInset={false}
header={listHeader}
/>
)
} }
return ( return (
<MediaGridList <MediaGridList
title={title}
titleAccessory={<ProfileHeaderButton />}
content={results} content={results}
paddingBottom={tabContentBottomInset} paddingBottom={tabContentBottomInset}
contentInset={false} contentInset={false}
+11 -13
View File
@@ -2,7 +2,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
import { Stack } from "expo-router" import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
export const unstable_settings = { export const unstable_settings = {
anchor: "index", anchor: "index",
@@ -16,19 +21,12 @@ export default function SearchLayout() {
screenLayout={renderTabScreenContent} screenLayout={renderTabScreenContent}
screenOptions={({ route }) => ({ screenOptions={({ route }) => ({
...baseOptions, ...baseOptions,
...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Search", title: tabStackScreenTitles[route.name] ?? "Search",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
@@ -35,7 +35,7 @@ export default function SearchScreen() {
: {})} : {})}
/> />
<SearchResults searchQuery={searchQuery} /> <SearchResults searchQuery={searchQuery} title="Search" />
</> </>
) )
} }
+30 -3
View File
@@ -4,9 +4,10 @@ import { tabletLayoutTransition } from "@/lib/tablet-motion"
import { TabletMediaGrid } from "@/components/tablet-media-grid" import { TabletMediaGrid } from "@/components/tablet-media-grid"
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout" import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
import { MusicEntityView } from "@/components/music-entity-view" import { MusicEntityView } from "@/components/music-entity-view"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { Link } from "expo-router" import { Link } from "expo-router"
import { Ionicons } from "@expo/vector-icons" import { Ionicons } from "@expo/vector-icons"
import { memo, useCallback, type ReactElement } from "react" import { memo, useCallback, type ReactElement, type ReactNode } from "react"
import { import {
FlatList, FlatList,
Platform, Platform,
@@ -300,17 +301,23 @@ export function MediaGridList({
onEndReached, onEndReached,
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title,
titleAccessory,
}: { }: {
content: MediaItem[] content: MediaItem[]
paddingBottom: number paddingBottom: number
onEndReached?: () => void onEndReached?: () => void
ListHeaderComponent?: ReactElement ListHeaderComponent?: ReactElement
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string
titleAccessory?: ReactNode
}) { }) {
const tabletLayout = useTabletLayout() const tabletLayout = useTabletLayout()
const { columns, cardWidth, onLayout, horizontalPadding, gap } = const { columns, cardWidth, onLayout, horizontalPadding, gap } =
useMediaGridLayout() useMediaGridLayout()
const colors = useThemeColors() const colors = useThemeColors()
const { ref, scrollY } = useScreenTitleScroll<FlatList<MediaItem>>()
const renderItem = useCallback( const renderItem = useCallback(
({ item }: ListRenderItemInfo<MediaItem>) => ( ({ item }: ListRenderItemInfo<MediaItem>) => (
<View style={{ width: cardWidth }}> <View style={{ width: cardWidth }}>
@@ -328,13 +335,32 @@ export function MediaGridList({
onEndReached={onEndReached} onEndReached={onEndReached}
ListHeaderComponent={ListHeaderComponent} ListHeaderComponent={ListHeaderComponent}
contentInset={contentInset} contentInset={contentInset}
title={title}
titleAccessory={titleAccessory}
renderCard={renderTabletCard} renderCard={renderTabletCard}
/> />
) )
} }
const header = title ? (
<View>
<ScreenTitle
title={title}
scrollY={scrollY}
accessory={titleAccessory}
// Inset grids already pad the whole list horizontally.
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
/>
{ListHeaderComponent}
</View>
) : (
ListHeaderComponent
)
return ( return (
<FlatList <Animated.FlatList
ref={ref}
scrollEventThrottle={16}
key={columns} key={columns}
onLayout={onLayout} onLayout={onLayout}
data={content} data={content}
@@ -351,6 +377,7 @@ export function MediaGridList({
paddingBottom, paddingBottom,
gap, gap,
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}), ...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
...(title ? { paddingTop: 0 } : {}),
}, },
]} ]}
columnWrapperStyle={[ columnWrapperStyle={[
@@ -359,7 +386,7 @@ export function MediaGridList({
{ gap }, { gap },
]} ]}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
ListHeaderComponent={ListHeaderComponent} ListHeaderComponent={header}
onEndReached={onEndReached} onEndReached={onEndReached}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}
/> />
+97
View File
@@ -0,0 +1,97 @@
import { useHeaderHeight } from "expo-router/react-navigation"
import type { Component, ReactNode } from "react"
import {
Platform,
StyleSheet,
Text,
type ScrollViewInstance,
type StyleProp,
type ViewStyle,
} from "react-native"
import Animated, {
useAnimatedRef,
useAnimatedStyle,
useScrollOffset,
type SharedValue,
} from "react-native-reanimated"
import { spacing, useThemeColors } from "@/lib/theme"
/**
* Tracks the scroll view that renders a `ScreenTitle`. Attach `ref` to that
* Reanimated `Animated.ScrollView` / `Animated.FlatList` and pass `scrollY`
* to the title.
*/
export function useScreenTitleScroll<
TScrollView extends Component | ScrollViewInstance,
>() {
const ref = useAnimatedRef<TScrollView>()
const scrollY = useScrollOffset(ref)
return { ref, scrollY }
}
/**
* iOS screen title rendered as the first item of a screen's scroll content,
* in place of the native large title (Apple Music style): it scrolls away
* with the content, never collapses into the bar, and stays put on
* pull-down. `accessory` (e.g. the profile button) sits on the same row and
* scrolls with it. Android keeps its native header, so this renders nothing.
*/
export function ScreenTitle({
title,
scrollY,
accessory,
style,
}: {
title: string
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
scrollY?: SharedValue<number>
accessory?: ReactNode
style?: StyleProp<ViewStyle>
}) {
const colors = useThemeColors()
// At rest the scroll offset is minus the automatic header inset, so any
// offset below that is overscroll the title should cancel out.
const headerHeight = useHeaderHeight()
const pinStyle = useAnimatedStyle(() => ({
transform: [
{
translateY: scrollY ? Math.min(0, scrollY.value + headerHeight) : 0,
},
],
}))
if (Platform.OS !== "ios") return null
return (
<Animated.View style={[styles.row, style, pinStyle]}>
<Text
accessibilityRole="header"
numberOfLines={2}
style={[styles.title, { color: colors.foreground }]}
>
{title}
</Text>
{accessory}
</Animated.View>
)
}
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
const styles = StyleSheet.create({
row: {
flexDirection: "row",
alignItems: "center",
gap: spacing.md,
paddingHorizontal: spacing.lg,
paddingTop: 3,
paddingBottom: 8,
},
title: {
flex: 1,
fontSize: 34,
lineHeight: 41,
fontWeight: "700",
letterSpacing: 0.37,
},
})
+32 -13
View File
@@ -1,13 +1,16 @@
import { memo, useCallback, useMemo } from "react" import { memo, useCallback, useMemo } from "react"
import { import {
FlatList, type FlatList,
StyleSheet, StyleSheet,
Text, Text,
View, View,
type ListRenderItemInfo, type ListRenderItemInfo,
} from "react-native" } from "react-native"
import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards" import { ContentCarousel } from "@/components/media-cards"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import type { MediaAction } from "@/components/media-context-menu" import type { MediaAction } from "@/components/media-context-menu"
import { tabContentBottomInset, SongListRow } from "@/components/player" import { tabContentBottomInset, SongListRow } from "@/components/player"
import { SongListSkeleton } from "@/components/skeletons" import { SongListSkeleton } from "@/components/skeletons"
@@ -19,8 +22,16 @@ import { api } from "@otunes/convex/_generated/api"
import type { BrowseSong, SearchSong } from "@otunes/convex/types" import type { BrowseSong, SearchSong } from "@otunes/convex/types"
import { spacing, useThemeColors } from "@/lib/theme" import { spacing, useThemeColors } from "@/lib/theme"
function SearchResultsBody({ searchQuery }: { searchQuery: string }) { function SearchResultsBody({
searchQuery,
title,
}: {
searchQuery: string
/** iOS `ScreenTitle`, shown above the results and while idle. */
title: string
}) {
const colors = useThemeColors() const colors = useThemeColors()
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
const { playFromSong } = usePlaybackActions() const { playFromSong } = usePlaybackActions()
const { isSongFavorite } = useFavorites() const { isSongFavorite } = useFavorites()
const { handleSongAction } = useMediaMenuActions() const { handleSongAction } = useMediaMenuActions()
@@ -76,16 +87,19 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
) )
if (isSearching) { if (isSearching) {
return <SongListSkeleton /> return (
} <SongListSkeleton
title={title}
if (!hasQuery) { titleAccessory={<ProfileHeaderButton />}
return <></> />
)
} }
return ( return (
<FlatList <Animated.FlatList
data={results?.songs ?? []} ref={ref}
scrollEventThrottle={16}
data={hasQuery ? (results?.songs ?? []) : []}
keyExtractor={(song) => song.id} keyExtractor={(song) => song.id}
style={{ flex: 1, backgroundColor: colors.background }} style={{ flex: 1, backgroundColor: colors.background }}
contentContainerStyle={{ paddingBottom: tabContentBottomInset }} contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
@@ -93,7 +107,12 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
keyboardShouldPersistTaps="handled" keyboardShouldPersistTaps="handled"
ListHeaderComponent={ ListHeaderComponent={
<> <>
{!hasResults ? ( <ScreenTitle
title={title}
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
/>
{hasQuery && !hasResults ? (
<View style={styles.empty}> <View style={styles.empty}>
<Text <Text
style={[styles.emptyText, { color: colors.mutedForeground }]} style={[styles.emptyText, { color: colors.mutedForeground }]}
@@ -103,13 +122,13 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
</View> </View>
) : null} ) : null}
{results?.artists.length ? ( {hasQuery && results?.artists.length ? (
<View style={styles.section}> <View style={styles.section}>
<ContentCarousel title="Artists" content={results.artists} /> <ContentCarousel title="Artists" content={results.artists} />
</View> </View>
) : null} ) : null}
{results?.albums.length ? ( {hasQuery && results?.albums.length ? (
<View style={styles.section}> <View style={styles.section}>
<ContentCarousel title="Albums" content={results.albums} /> <ContentCarousel title="Albums" content={results.albums} />
</View> </View>
@@ -118,7 +137,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
} }
renderItem={renderItem} renderItem={renderItem}
ListFooterComponent={ ListFooterComponent={
playlistResults && playlistResults.length > 0 ? ( hasQuery && playlistResults && playlistResults.length > 0 ? (
<View style={styles.section}> <View style={styles.section}>
<ContentCarousel title="Playlists" content={playlistResults} /> <ContentCarousel title="Playlists" content={playlistResults} />
</View> </View>
+70 -5
View File
@@ -9,6 +9,7 @@ import {
collectionInset, collectionInset,
} from "@/components/collection-list" } from "@/components/collection-list"
import { tabletCardTextHeight } from "@/components/tablet-media-grid" import { tabletCardTextHeight } from "@/components/tablet-media-grid"
import { ScreenTitle } from "@/components/screen-title"
import { Link } from "expo-router" import { Link } from "expo-router"
import { useHeaderHeight } from "expo-router/react-navigation" import { useHeaderHeight } from "expo-router/react-navigation"
import Reanimated from "react-native-reanimated" import Reanimated from "react-native-reanimated"
@@ -151,9 +152,18 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
)) ))
} }
export function SongListSkeleton({ rows = 10 }: { rows?: number }) { export function SongListSkeleton({
rows = 10,
title,
titleAccessory,
}: {
rows?: number
title?: string
titleAccessory?: ReactNode
}) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
{title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
<SongRows rows={rows} /> <SongRows rows={rows} />
</SkeletonScreen> </SkeletonScreen>
) )
@@ -234,23 +244,54 @@ export function MediaGridSkeleton({
items = 6, items = 6,
contentInset = true, contentInset = true,
header, header,
title,
titleAccessory,
}: { }: {
items?: number items?: number
contentInset?: boolean contentInset?: boolean
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */ /** The loaded list's `ListHeaderComponent`, so it keeps its position. */
header?: ReactNode header?: ReactNode
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
title?: string
titleAccessory?: ReactNode
}) { }) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
<MediaGridContent <MediaGridContent
items={items} items={items}
contentInset={contentInset} contentInset={contentInset && !title}
header={header} header={
title ? (
<>
<MediaGridTitle title={title} accessory={titleAccessory} />
{header}
</>
) : (
header
)
}
/> />
</SkeletonScreen> </SkeletonScreen>
) )
} }
function MediaGridTitle({
title,
accessory,
}: {
title: string
accessory?: ReactNode
}) {
const { horizontalPadding } = useMediaGridLayout()
return (
<ScreenTitle
title={title}
accessory={accessory}
style={{ paddingHorizontal: horizontalPadding }}
/>
)
}
export function CarouselSkeleton() { export function CarouselSkeleton() {
return ( return (
<View style={styles.carousel}> <View style={styles.carousel}>
@@ -264,10 +305,21 @@ export function CarouselSkeleton() {
) )
} }
export function HomeSkeleton() { export function HomeSkeleton({
title,
titleAccessory,
}: {
title: string
titleAccessory?: ReactNode
}) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
<View style={styles.home}> <View style={styles.home}>
<ScreenTitle
title={title}
accessory={titleAccessory}
style={styles.homeTitle}
/>
<CarouselSkeleton /> <CarouselSkeleton />
<CarouselSkeleton /> <CarouselSkeleton />
</View> </View>
@@ -388,10 +440,17 @@ export function CollectionDetailSkeleton({
) )
} }
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) { export function ArtistListSkeleton({
rows = 12,
title,
}: {
rows?: number
title?: string
}) {
const colors = useThemeColors() const colors = useThemeColors()
return ( return (
<SkeletonScreen> <SkeletonScreen>
{title ? <ScreenTitle title={title} /> : null}
{Array.from({ length: rows }, (_, index) => ( {Array.from({ length: rows }, (_, index) => (
<View <View
key={index} key={index}
@@ -456,6 +515,12 @@ const styles = StyleSheet.create({
carousel: { gap: spacing.md, overflow: "hidden" }, carousel: { gap: spacing.md, overflow: "hidden" },
carouselRow: { flexDirection: "row", gap: spacing.md }, carouselRow: { flexDirection: "row", gap: spacing.md },
home: { padding: spacing.lg, gap: spacing.xl }, home: { padding: spacing.lg, gap: spacing.xl },
// Mirrors the home screen's title spacing.
homeTitle: {
paddingHorizontal: 0,
marginTop: -spacing.lg,
marginBottom: -spacing.md,
},
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm }, centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
actions: { actions: {
flexDirection: "row", flexDirection: "row",
+24 -5
View File
@@ -4,9 +4,10 @@ import {
useRef, useRef,
useState, useState,
type ReactElement, type ReactElement,
type ReactNode,
} from "react" } from "react"
import { import {
ScrollView, type ScrollViewInstance,
View, View,
type NativeSyntheticEvent, type NativeSyntheticEvent,
type NativeScrollEvent, type NativeScrollEvent,
@@ -15,6 +16,7 @@ import Animated from "react-native-reanimated"
import { useSafeAreaInsets } from "react-native-safe-area-context" import { useSafeAreaInsets } from "react-native-safe-area-context"
import type { MediaItem } from "@/components/media-cards" import type { MediaItem } from "@/components/media-cards"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout" import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
import { tabletLayoutTransition } from "@/lib/tablet-motion" import { tabletLayoutTransition } from "@/lib/tablet-motion"
import { useThemeColors } from "@/lib/theme" import { useThemeColors } from "@/lib/theme"
@@ -28,6 +30,9 @@ type GridProps = {
onEndReached?: () => void onEndReached?: () => void
ListHeaderComponent?: ReactElement ListHeaderComponent?: ReactElement
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string
titleAccessory?: ReactNode
renderCard: (item: MediaItem, width: number) => ReactElement renderCard: (item: MediaItem, width: number) => ReactElement
} }
@@ -41,9 +46,13 @@ export function TabletMediaGrid({
onEndReached, onEndReached,
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title,
titleAccessory,
renderCard, renderCard,
}: GridProps) { }: GridProps) {
const colors = useThemeColors() const colors = useThemeColors()
const { ref, scrollY: titleScrollY } =
useScreenTitleScroll<ScrollViewInstance>()
const insets = useSafeAreaInsets() const insets = useSafeAreaInsets()
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } = const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
useMediaGridLayout() useMediaGridLayout()
@@ -102,18 +111,28 @@ export function TabletMediaGrid({
setViewportHeight(event.nativeEvent.layout.height) setViewportHeight(event.nativeEvent.layout.height)
}} }}
> >
<ScrollView <Animated.ScrollView
ref={ref}
onScroll={onScroll} onScroll={onScroll}
scrollEventThrottle={32} // Every frame, so the title pins smoothly on pull-down.
scrollEventThrottle={16}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
contentContainerStyle={{ contentContainerStyle={{
paddingTop: contentInset ? horizontalPadding : 0, paddingTop: contentInset && !title ? horizontalPadding : 0,
paddingBottom: paddingBottom + insets.bottom, paddingBottom: paddingBottom + insets.bottom,
}} }}
> >
<View <View
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)} onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
> >
{title ? (
<ScreenTitle
title={title}
scrollY={titleScrollY}
accessory={titleAccessory}
style={{ paddingHorizontal: horizontalPadding }}
/>
) : null}
{ListHeaderComponent} {ListHeaderComponent}
</View> </View>
<View style={{ height: gridHeight }}> <View style={{ height: gridHeight }}>
@@ -136,7 +155,7 @@ export function TabletMediaGrid({
) )
})} })}
</View> </View>
</ScrollView> </Animated.ScrollView>
</Animated.View> </Animated.View>
) )
} }
+13 -1
View File
@@ -17,13 +17,25 @@ export const tabStackScreenTitles: Record<string, string> = {
"downloads/other": "Other Downloaded Songs", "downloads/other": "Other Downloaded Songs",
} }
/**
* iOS tab stacks render their titles in the scroll content with
* `ScreenTitle`, so the bar keeps the title (for back menus) but hides it.
*/
export const inlineTitleOptions: StackScreenOptions =
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
/** Tab roots show the profile button in the header, except on iOS where `ScreenTitle` holds it. */
export function showHeaderProfile(routeName: string) {
return routeName === "index" && Platform.OS !== "ios"
}
export function useStackScreenOptions( export function useStackScreenOptions(
overrides?: StackScreenOptions overrides?: StackScreenOptions
): StackScreenOptions { ): StackScreenOptions {
const theme = useThemeColors() const theme = useThemeColors()
return { return {
headerLargeTitle: true, headerLargeTitle: false,
headerTransparent: true, headerTransparent: true,
headerTintColor: theme.foreground, headerTintColor: theme.foreground,
headerLargeTitleStyle: { color: theme.foreground }, headerLargeTitleStyle: { color: theme.foreground },