Compare commits

..
19 changed files with 161 additions and 92 deletions

No files matched your search

+5 -12
View File
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function HomeLayout() {
...baseOptions,
...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Home",
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
unstable_headerRightItems:
route.name === "index"
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
// iOS shows the profile button inline with the screen title instead.
headerRight: showHeaderProfile(route.name)
? () => <ProfileHeaderButton />
: undefined,
})}
/>
)
+10 -2
View File
@@ -5,6 +5,7 @@ import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards"
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 { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { api } from "@otunes/convex/_generated/api"
@@ -56,7 +57,9 @@ export default function HomeScreen() {
(result) => result.status === "LoadingFirstPage" && !result.isCached
)
if (isLoading) {
return <HomeSkeleton title="Home" />
return (
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
)
}
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
@@ -73,7 +76,12 @@ export default function HomeScreen() {
]}
contentInsetAdjustmentBehavior="automatic"
>
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} />
<ScreenTitle
title="Home"
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
style={styles.title}
/>
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
</Animated.ScrollView>
)
@@ -5,6 +5,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
@@ -26,18 +27,10 @@ export default function LibraryLayout() {
title:
tabStackScreenTitles[route.name] ??
(tabletLayout ? "Recently Added" : "Library"),
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
unstable_headerRightItems:
route.name === "index"
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
// iOS shows the profile button inline with the screen title instead.
headerRight: showHeaderProfile(route.name)
? () => <ProfileHeaderButton />
: undefined,
})}
/>
)
@@ -8,6 +8,7 @@ import { Ionicons } from "@expo/vector-icons"
import { MediaGridList } from "@/components/media-cards"
import { tabContentBottomInset } from "@/components/player"
import { MediaGridSkeleton } from "@/components/skeletons"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api"
@@ -128,6 +129,7 @@ export default function LibraryScreen() {
return (
<MediaGridSkeleton
title={title}
titleAccessory={<ProfileHeaderButton />}
contentInset={false}
header={listHeader}
/>
@@ -137,6 +139,7 @@ export default function LibraryScreen() {
return (
<MediaGridList
title={title}
titleAccessory={<ProfileHeaderButton />}
content={results}
paddingBottom={tabContentBottomInset}
contentInset={false}
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import {
inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles,
useStackScreenOptions,
} from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function SearchLayout() {
...baseOptions,
...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Search",
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
unstable_headerRightItems:
route.name === "index"
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
// iOS shows the profile button inline with the screen title instead.
headerRight: showHeaderProfile(route.name)
? () => <ProfileHeaderButton />
: undefined,
})}
/>
)
+5 -1
View File
@@ -7,7 +7,7 @@ import { MusicEntityView } from "@/components/music-entity-view"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { Link } from "expo-router"
import { Ionicons } from "@expo/vector-icons"
import { memo, useCallback, type ReactElement } from "react"
import { memo, useCallback, type ReactElement, type ReactNode } from "react"
import {
FlatList,
Platform,
@@ -302,6 +302,7 @@ export function MediaGridList({
ListHeaderComponent,
contentInset = true,
title,
titleAccessory,
}: {
content: MediaItem[]
paddingBottom: number
@@ -310,6 +311,7 @@ export function MediaGridList({
contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string
titleAccessory?: ReactNode
}) {
const tabletLayout = useTabletLayout()
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
@@ -334,6 +336,7 @@ export function MediaGridList({
ListHeaderComponent={ListHeaderComponent}
contentInset={contentInset}
title={title}
titleAccessory={titleAccessory}
renderCard={renderTabletCard}
/>
)
@@ -344,6 +347,7 @@ export function MediaGridList({
<ScreenTitle
title={title}
scrollY={scrollY}
accessory={titleAccessory}
// Inset grids already pad the whole list horizontally.
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
/>
+29 -16
View File
@@ -1,11 +1,12 @@
import { useHeaderHeight } from "expo-router/react-navigation"
import type { Component } from "react"
import type { Component, ReactNode } from "react"
import {
Platform,
StyleSheet,
Text,
type ScrollViewInstance,
type StyleProp,
type TextStyle,
type ViewStyle,
} from "react-native"
import Animated, {
useAnimatedRef,
@@ -33,17 +34,20 @@ export function useScreenTitleScroll<
* 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. Android keeps its native header title, so this renders nothing.
* 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>
style?: StyleProp<TextStyle>
accessory?: ReactNode
style?: StyleProp<ViewStyle>
}) {
const colors = useThemeColors()
// At rest the scroll offset is minus the automatic header inset, so any
@@ -60,25 +64,34 @@ export function ScreenTitle({
if (Platform.OS !== "ios") return null
return (
<Animated.Text
accessibilityRole="header"
numberOfLines={2}
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
>
{title}
</Animated.Text>
<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({
title: {
fontSize: 34,
lineHeight: 41,
fontWeight: "700",
letterSpacing: 0.37,
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,
},
})
+12 -2
View File
@@ -9,6 +9,7 @@ import {
import Animated from "react-native-reanimated"
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 { tabContentBottomInset, SongListRow } from "@/components/player"
@@ -86,7 +87,12 @@ function SearchResultsBody({
)
if (isSearching) {
return <SongListSkeleton title={title} />
return (
<SongListSkeleton
title={title}
titleAccessory={<ProfileHeaderButton />}
/>
)
}
return (
@@ -101,7 +107,11 @@ function SearchResultsBody({
keyboardShouldPersistTaps="handled"
ListHeaderComponent={
<>
<ScreenTitle title={title} scrollY={scrollY} />
<ScreenTitle
title={title}
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
/>
{hasQuery && !hasResults ? (
<View style={styles.empty}>
<Text
+26 -5
View File
@@ -155,13 +155,15 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
export function SongListSkeleton({
rows = 10,
title,
titleAccessory,
}: {
rows?: number
title?: string
titleAccessory?: ReactNode
}) {
return (
<SkeletonScreen>
{title ? <ScreenTitle title={title} /> : null}
{title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
<SongRows rows={rows} />
</SkeletonScreen>
)
@@ -243,6 +245,7 @@ export function MediaGridSkeleton({
contentInset = true,
header,
title,
titleAccessory,
}: {
items?: number
contentInset?: boolean
@@ -250,6 +253,7 @@ export function MediaGridSkeleton({
header?: ReactNode
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
title?: string
titleAccessory?: ReactNode
}) {
return (
<SkeletonScreen>
@@ -259,7 +263,7 @@ export function MediaGridSkeleton({
header={
title ? (
<>
<MediaGridTitle title={title} />
<MediaGridTitle title={title} accessory={titleAccessory} />
{header}
</>
) : (
@@ -271,11 +275,18 @@ export function MediaGridSkeleton({
)
}
function MediaGridTitle({ title }: { title: string }) {
function MediaGridTitle({
title,
accessory,
}: {
title: string
accessory?: ReactNode
}) {
const { horizontalPadding } = useMediaGridLayout()
return (
<ScreenTitle
title={title}
accessory={accessory}
style={{ paddingHorizontal: horizontalPadding }}
/>
)
@@ -294,11 +305,21 @@ export function CarouselSkeleton() {
)
}
export function HomeSkeleton({ title }: { title: string }) {
export function HomeSkeleton({
title,
titleAccessory,
}: {
title: string
titleAccessory?: ReactNode
}) {
return (
<SkeletonScreen>
<View style={styles.home}>
<ScreenTitle title={title} style={styles.homeTitle} />
<ScreenTitle
title={title}
accessory={titleAccessory}
style={styles.homeTitle}
/>
<CarouselSkeleton />
<CarouselSkeleton />
</View>
@@ -4,6 +4,7 @@ import {
useRef,
useState,
type ReactElement,
type ReactNode,
} from "react"
import {
type ScrollViewInstance,
@@ -31,6 +32,7 @@ type GridProps = {
contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string
titleAccessory?: ReactNode
renderCard: (item: MediaItem, width: number) => ReactElement
}
@@ -45,6 +47,7 @@ export function TabletMediaGrid({
ListHeaderComponent,
contentInset = true,
title,
titleAccessory,
renderCard,
}: GridProps) {
const colors = useThemeColors()
@@ -126,6 +129,7 @@ export function TabletMediaGrid({
<ScreenTitle
title={title}
scrollY={titleScrollY}
accessory={titleAccessory}
style={{ paddingHorizontal: horizontalPadding }}
/>
) : null}
+5
View File
@@ -24,6 +24,11 @@ export const tabStackScreenTitles: Record<string, string> = {
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(
overrides?: StackScreenOptions
): StackScreenOptions {
+3
View File
@@ -114,6 +114,7 @@ export function AlbumView({
}) {
const {
isSongFavorite,
areSongsFavorite,
isAlbumFavorite,
toggleSongFavorite,
toggleAlbumFavorite,
@@ -154,6 +155,7 @@ export function AlbumView({
handlePointerDown,
prepareContextMenu,
} = useTrackSelection(album.tracks, validHighlightedSongId)
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = React.useMemo(
() =>
@@ -413,6 +415,7 @@ export function AlbumView({
isFavorite={isSongFavorite(track.id)}
selectedCount={selectedCount}
selectionStationArtistId={album.artist.id}
selectionFavorited={selectionFavorited}
isNowPlaying={currentSongId === track.id}
onPointerDown={handlePointerDown}
onSelect={handleRowSelect}
+12 -21
View File
@@ -37,7 +37,8 @@ type FavoritesContextValue = {
) => Promise<boolean>
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
/** True when `songIds` is non-empty and every song is favorited. */
areSongsFavorite: (songIds: Iterable<string>) => boolean
}
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
@@ -130,26 +131,16 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
[songIds, favoriteSong, unfavoriteSong]
)
const favoriteSongs = React.useCallback(
async (ids: Id<"songs">[]) => {
const unique = [...new Set(ids)]
if (unique.length === 0) {
return
}
try {
await favoriteSongsMutation({ songIds: unique })
toast.success(
unique.length > 1
? `Favorited ${unique.length} songs`
: "Added to favorites"
)
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to update favorites"
)
const areSongsFavorite = React.useCallback(
(ids: Iterable<string>) => {
let any = false
for (const id of ids) {
if (!songIds.has(id)) return false
any = true
}
return any
},
[favoriteSongsMutation]
[songIds]
)
const toggleSongsFavorite = React.useCallback(
@@ -232,7 +223,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
toggleSongsFavorite,
toggleAlbumFavorite,
toggleArtistFavorite,
favoriteSongs,
areSongsFavorite,
}),
[
isSongFavorite,
@@ -242,7 +233,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
toggleSongsFavorite,
toggleAlbumFavorite,
toggleArtistFavorite,
favoriteSongs,
areSongsFavorite,
]
)
+4 -1
View File
@@ -48,7 +48,8 @@ export function OtherDownloadsView() {
[songs]
)
const { isSongFavorite, toggleSongFavorite } = useFavorites()
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
useFavorites()
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
const {
selectedIds,
@@ -62,6 +63,7 @@ export function OtherDownloadsView() {
() => stationArtistId(songs, selectedIds),
[songs, selectedIds]
)
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = useMemo(
() =>
getSelectionRangePositions(
@@ -140,6 +142,7 @@ export function OtherDownloadsView() {
isFavorite={isSongFavorite(songs[index].id)}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
onPointerDown={handlePointerDown}
onSelect={handleRowSelect}
onPlay={handleRowPlay}
+9 -2
View File
@@ -74,8 +74,12 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
currentUser === undefined
? playlist.isOwner
: currentUser?._id === playlist.owner.id
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
useFavorites()
const {
isSongFavorite,
areSongsFavorite,
toggleSongFavorite,
toggleSongsFavorite,
} = useFavorites()
const currentSongId = useCurrentSongId()
const {
playInOrder,
@@ -143,6 +147,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
() => stationArtistId(songs, selectedIds),
[songs, selectedIds]
)
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = React.useMemo(
() =>
@@ -465,6 +470,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
onAction={handlePlaylistMediaAction}
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
showFavorite={!isFavorites}
favorited={areSongsFavorite(playlistSongIds)}
downloaded={playlistDownloaded}
trackRowTrigger={false}
triggerVariant="secondary"
@@ -522,6 +528,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
selectionPosition={selectionPositions[index]}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
downloadCollection={downloadRef}
showFavoriteInMenu={!isFavorites}
+7 -1
View File
@@ -244,7 +244,7 @@ export function QueuePanel() {
prepareContextMenu,
clearSelection,
} = useTrackSelection(selectionItems)
const { isSongFavorite } = useFavorites()
const { isSongFavorite, areSongsFavorite } = useFavorites()
const { runSongsAction } = useMediaActions()
/** The rows a menu acts on: the selection, else just the clicked row. */
@@ -268,6 +268,11 @@ export function QueuePanel() {
),
[selectableQueue, selectedIds]
)
const selectionFavorited = areSongsFavorite(
selectableQueue.flatMap((item) =>
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
)
)
const handleMediaAction = React.useCallback(
(action: MediaContextAction, selectionId: string) => {
@@ -453,6 +458,7 @@ export function QueuePanel() {
isFavorite={isSongFavorite(item.song.id)}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
removeLabel="Remove from Queue"
selectionPosition={selectionPositions[index]}
isDragging={draggingIndices.has(index)}
+4 -1
View File
@@ -47,7 +47,8 @@ const SONGS_PAGE_SIZE = 50
const estimateSongRowSize = () => 56
export function SongsView() {
const { isSongFavorite, toggleSongFavorite } = useFavorites()
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
useFavorites()
const { playFromLibrarySong } = usePlaybackActions()
const [sortKey, setSortKey] = useState<SortKey>("title")
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
@@ -98,6 +99,7 @@ export function SongsView() {
() => stationArtistId(songs, selectedIds),
[songs, selectedIds]
)
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = useMemo(
() =>
@@ -222,6 +224,7 @@ export function SongsView() {
isFavorite={isSongFavorite(songs[index].id)}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
onPointerDown={handlePointerDown}
onSelect={handleRowSelect}
onPlay={handleRowPlay}
+7 -1
View File
@@ -68,6 +68,8 @@ export type TrackRowProps = {
selectedCount?: number
/** Station artist for the selection when this row is selected. */
selectionStationArtistId?: string
/** Whether every selected song is favorited, when this row is selected. */
selectionFavorited?: boolean
playlistLabel?: string
showFavoriteInMenu?: boolean
/** Adds a destructive menu item calling `onRemove`. */
@@ -268,6 +270,7 @@ function TrackRowComponent({
isDragging = false,
selectedCount = 0,
selectionStationArtistId,
selectionFavorited,
playlistLabel,
showFavoriteInMenu = true,
removeLabel,
@@ -345,7 +348,10 @@ function TrackRowComponent({
onAction: (action) => onMediaAction(action, rowId),
playlistLabel,
showFavorite: showFavoriteInMenu,
favorited: isFavorite,
favorited:
inRange && selectedCount > 0
? (selectionFavorited ?? isFavorite)
: isFavorite,
navigation: {
artist: { id: song.artist.id },
album: { id: song.album.id },
+6 -3
View File
@@ -26,7 +26,8 @@ function songsTitle(songIds: readonly string[]) {
export function useMediaActions() {
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
useFavorites()
const { runQueueAction, createStation } = useQueueMediaActions()
const convex = useConvex()
const cacheScope = useCacheScope()
@@ -44,7 +45,8 @@ export function useMediaActions() {
if (stationArtist) void createStation(stationArtist)
break
case "favorite":
void favoriteSongs(songIds)
// Unfavorite only when every song already is, matching the menu label.
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
break
case "playlist":
openAddToPlaylist(songIds)
@@ -73,7 +75,8 @@ export function useMediaActions() {
},
[
createStation,
favoriteSongs,
areSongsFavorite,
toggleSongsFavorite,
openAddToPlaylist,
runQueueAction,
requestDownload,