Compare commits
3
Commits
No files matched your search
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
|
|||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import {
|
import {
|
||||||
inlineTitleOptions,
|
inlineTitleOptions,
|
||||||
|
showHeaderProfile,
|
||||||
tabStackScreenTitles,
|
tabStackScreenTitles,
|
||||||
useStackScreenOptions,
|
useStackScreenOptions,
|
||||||
} from "@/lib/navigation"
|
} from "@/lib/navigation"
|
||||||
@@ -22,18 +23,10 @@ export default function HomeLayout() {
|
|||||||
...baseOptions,
|
...baseOptions,
|
||||||
...inlineTitleOptions,
|
...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,
|
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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 { 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"
|
||||||
@@ -56,7 +57,9 @@ export default function HomeScreen() {
|
|||||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||||
)
|
)
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <HomeSkeleton title="Home" />
|
return (
|
||||||
|
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||||
@@ -73,7 +76,12 @@ export default function HomeScreen() {
|
|||||||
]}
|
]}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
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} />
|
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||||
</Animated.ScrollView>
|
</Animated.ScrollView>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Stack } from "expo-router"
|
|||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import {
|
import {
|
||||||
inlineTitleOptions,
|
inlineTitleOptions,
|
||||||
|
showHeaderProfile,
|
||||||
tabStackScreenTitles,
|
tabStackScreenTitles,
|
||||||
useStackScreenOptions,
|
useStackScreenOptions,
|
||||||
} from "@/lib/navigation"
|
} from "@/lib/navigation"
|
||||||
@@ -26,18 +27,10 @@ export default function LibraryLayout() {
|
|||||||
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,
|
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -128,6 +129,7 @@ export default function LibraryScreen() {
|
|||||||
return (
|
return (
|
||||||
<MediaGridSkeleton
|
<MediaGridSkeleton
|
||||||
title={title}
|
title={title}
|
||||||
|
titleAccessory={<ProfileHeaderButton />}
|
||||||
contentInset={false}
|
contentInset={false}
|
||||||
header={listHeader}
|
header={listHeader}
|
||||||
/>
|
/>
|
||||||
@@ -137,6 +139,7 @@ export default function LibraryScreen() {
|
|||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
title={title}
|
title={title}
|
||||||
|
titleAccessory={<ProfileHeaderButton />}
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={tabContentBottomInset}
|
paddingBottom={tabContentBottomInset}
|
||||||
contentInset={false}
|
contentInset={false}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
|
|||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import {
|
import {
|
||||||
inlineTitleOptions,
|
inlineTitleOptions,
|
||||||
|
showHeaderProfile,
|
||||||
tabStackScreenTitles,
|
tabStackScreenTitles,
|
||||||
useStackScreenOptions,
|
useStackScreenOptions,
|
||||||
} from "@/lib/navigation"
|
} from "@/lib/navigation"
|
||||||
@@ -22,18 +23,10 @@ export default function SearchLayout() {
|
|||||||
...baseOptions,
|
...baseOptions,
|
||||||
...inlineTitleOptions,
|
...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,
|
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ import {
|
|||||||
View,
|
View,
|
||||||
type ScrollViewInstance,
|
type ScrollViewInstance,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import Animated, {
|
|
||||||
cancelAnimation,
|
|
||||||
Easing,
|
|
||||||
useAnimatedStyle,
|
|
||||||
useSharedValue,
|
|
||||||
withTiming,
|
|
||||||
type SharedValue,
|
|
||||||
} from "react-native-reanimated"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
usePlaybackActions,
|
usePlaybackActions,
|
||||||
@@ -26,7 +18,6 @@ import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
|||||||
import {
|
import {
|
||||||
activeLineIndex,
|
activeLineIndex,
|
||||||
type LyricLine,
|
type LyricLine,
|
||||||
type LyricWord,
|
|
||||||
type Lyrics,
|
type Lyrics,
|
||||||
} from "@otunes/convex/client/lyrics"
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
@@ -34,8 +25,6 @@ import {
|
|||||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
/** Where the playing line sits, as a share of the view's height from the top. */
|
/** Where the playing line sits, as a share of the view's height from the top. */
|
||||||
const ACTIVE_LINE_POSITION = 0.12
|
const ACTIVE_LINE_POSITION = 0.12
|
||||||
/** Blur radius by distance from the playing line; farther lines share the last. */
|
|
||||||
const LINE_BLUR = [0, 1, 2, 3]
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
||||||
@@ -81,22 +70,19 @@ function LyricsLines({
|
|||||||
const scrollRef = useRef<ScrollViewInstance>(null)
|
const scrollRef = useRef<ScrollViewInstance>(null)
|
||||||
const lineOffsets = useRef<number[]>([])
|
const lineOffsets = useRef<number[]>([])
|
||||||
const [height, setHeight] = useState(0)
|
const [height, setHeight] = useState(0)
|
||||||
// While the listener scrolls, lines stay sharp and the view stays put.
|
const manualScrollAt = useRef(0)
|
||||||
const [browsing, setBrowsing] = useState(false)
|
|
||||||
const browseTimer = useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
||||||
|
|
||||||
useEffect(() => () => clearTimeout(browseTimer.current), [])
|
|
||||||
|
|
||||||
const scrollToLine = useCallback(
|
const scrollToLine = useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
const y = lineOffsets.current[Math.max(index, 0)]
|
const y = lineOffsets.current[Math.max(index, 0)]
|
||||||
if (y === undefined || !synced || height === 0 || browsing) return
|
if (y === undefined || !synced || height === 0) return
|
||||||
|
if (Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS) return
|
||||||
scrollRef.current?.scrollTo({
|
scrollRef.current?.scrollTo({
|
||||||
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
||||||
animated: true,
|
animated: true,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[height, synced, browsing]
|
[height, synced]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -120,20 +106,11 @@ function LyricsLines({
|
|||||||
(seconds: number) => {
|
(seconds: number) => {
|
||||||
seekTo(seconds)
|
seekTo(seconds)
|
||||||
setIsPlaying(true)
|
setIsPlaying(true)
|
||||||
clearTimeout(browseTimer.current)
|
manualScrollAt.current = 0
|
||||||
setBrowsing(false)
|
|
||||||
},
|
},
|
||||||
[seekTo, setIsPlaying]
|
[seekTo, setIsPlaying]
|
||||||
)
|
)
|
||||||
|
|
||||||
const releaseScroll = () => {
|
|
||||||
clearTimeout(browseTimer.current)
|
|
||||||
browseTimer.current = setTimeout(
|
|
||||||
() => setBrowsing(false),
|
|
||||||
MANUAL_SCROLL_HOLD_MS
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const lineStyle = useMemo(
|
const lineStyle = useMemo(
|
||||||
() => ({ fontSize, lineHeight: Math.round(fontSize * 1.18) }),
|
() => ({ fontSize, lineHeight: Math.round(fontSize * 1.18) }),
|
||||||
[fontSize]
|
[fontSize]
|
||||||
@@ -150,12 +127,12 @@ function LyricsLines({
|
|||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
||||||
onScrollBeginDrag={() => {
|
onScrollBeginDrag={() => {
|
||||||
clearTimeout(browseTimer.current)
|
manualScrollAt.current = Date.now()
|
||||||
setBrowsing(true)
|
}}
|
||||||
|
onMomentumScrollEnd={() => {
|
||||||
|
// Hold from when the scroll settles, not when the finger lifted.
|
||||||
|
if (manualScrollAt.current > 0) manualScrollAt.current = Date.now()
|
||||||
}}
|
}}
|
||||||
// Hold from when the scroll settles, not when the finger lifted.
|
|
||||||
onScrollEndDrag={releaseScroll}
|
|
||||||
onMomentumScrollEnd={releaseScroll}
|
|
||||||
>
|
>
|
||||||
{lyrics.lines.map((line, index) =>
|
{lyrics.lines.map((line, index) =>
|
||||||
synced ? (
|
synced ? (
|
||||||
@@ -163,14 +140,10 @@ function LyricsLines({
|
|||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
line={line}
|
line={line}
|
||||||
distance={
|
state={
|
||||||
browsing
|
index === active ? "active" : index < active ? "past" : "next"
|
||||||
? 0
|
|
||||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
|
||||||
}
|
}
|
||||||
active={index === active}
|
|
||||||
time={index === active ? time : null}
|
time={index === active ? time : null}
|
||||||
isPlaying={isPlaying}
|
|
||||||
colors={colors}
|
colors={colors}
|
||||||
textStyle={lineStyle}
|
textStyle={lineStyle}
|
||||||
onSelect={playFrom}
|
onSelect={playFrom}
|
||||||
@@ -198,17 +171,14 @@ function LyricsLines({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One timed line, blurred by its `distance` from the playing line. Only the
|
* One timed line. Only the playing line gets the time, so the others skip
|
||||||
* playing line gets the time, so the others skip re-rendering as the song
|
* re-rendering as the song plays.
|
||||||
* plays.
|
|
||||||
*/
|
*/
|
||||||
const SyncedLine = memo(function SyncedLine({
|
const SyncedLine = memo(function SyncedLine({
|
||||||
index,
|
index,
|
||||||
line,
|
line,
|
||||||
distance,
|
state,
|
||||||
active,
|
|
||||||
time,
|
time,
|
||||||
isPlaying,
|
|
||||||
colors,
|
colors,
|
||||||
textStyle,
|
textStyle,
|
||||||
onSelect,
|
onSelect,
|
||||||
@@ -216,155 +186,58 @@ const SyncedLine = memo(function SyncedLine({
|
|||||||
}: {
|
}: {
|
||||||
index: number
|
index: number
|
||||||
line: LyricLine
|
line: LyricLine
|
||||||
distance: number
|
state: "past" | "active" | "next"
|
||||||
active: boolean
|
|
||||||
time: number | null
|
time: number | null
|
||||||
isPlaying: boolean
|
|
||||||
colors: NowPlayingColors
|
colors: NowPlayingColors
|
||||||
textStyle: { fontSize: number; lineHeight: number }
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
onSelect: (seconds: number) => void
|
onSelect: (seconds: number) => void
|
||||||
onLayoutY: (index: number, y: number) => void
|
onLayoutY: (index: number, y: number) => void
|
||||||
}) {
|
}) {
|
||||||
const blur = LINE_BLUR[distance]
|
const active = state === "active"
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => onSelect(line.start ?? 0)}
|
onPress={() => onSelect(line.start ?? 0)}
|
||||||
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityHint="Plays from this line"
|
accessibilityHint="Plays from this line"
|
||||||
style={[styles.line, blur > 0 && { filter: [{ blur }] }]}
|
style={styles.line}
|
||||||
>
|
>
|
||||||
{active && line.words && time !== null ? (
|
<Text
|
||||||
<FilledWords
|
style={[
|
||||||
words={line.words}
|
styles.lineText,
|
||||||
time={time}
|
textStyle,
|
||||||
isPlaying={isPlaying}
|
{
|
||||||
colors={colors}
|
color:
|
||||||
textStyle={textStyle}
|
active && !line.words ? colors.foreground : colors.lyricsInactive,
|
||||||
/>
|
},
|
||||||
) : (
|
]}
|
||||||
<Text
|
>
|
||||||
style={[
|
{active && line.words
|
||||||
styles.lineText,
|
? line.words.map((word, wordIndex) => (
|
||||||
textStyle,
|
<Text
|
||||||
{
|
key={wordIndex}
|
||||||
color:
|
style={{
|
||||||
active && !line.words
|
color:
|
||||||
? colors.foreground
|
time !== null && time >= word.start
|
||||||
: colors.lyricsInactive,
|
? colors.foreground
|
||||||
},
|
: colors.lyricsUnsung,
|
||||||
]}
|
}}
|
||||||
>
|
>
|
||||||
{line.text}
|
{word.text}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
))
|
||||||
|
: line.text}
|
||||||
|
</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* The playing line's words, each wiping from dim to bright as it is sung.
|
|
||||||
* Reanimated runs the wipe; playback updates only re-anchor it.
|
|
||||||
*/
|
|
||||||
function FilledWords({
|
|
||||||
words,
|
|
||||||
time,
|
|
||||||
isPlaying,
|
|
||||||
colors,
|
|
||||||
textStyle,
|
|
||||||
}: {
|
|
||||||
words: LyricWord[]
|
|
||||||
time: number
|
|
||||||
isPlaying: boolean
|
|
||||||
colors: NowPlayingColors
|
|
||||||
textStyle: { fontSize: number; lineHeight: number }
|
|
||||||
}) {
|
|
||||||
const sung = useSharedValue(time)
|
|
||||||
const end = words.at(-1)?.end ?? time
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
cancelAnimation(sung)
|
|
||||||
sung.value = time
|
|
||||||
if (isPlaying && end > time) {
|
|
||||||
sung.value = withTiming(end, {
|
|
||||||
duration: (end - time) * 1000,
|
|
||||||
easing: Easing.linear,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [sung, time, isPlaying, end])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}>
|
|
||||||
{words.map((word, index) => (
|
|
||||||
<FilledWord
|
|
||||||
key={index}
|
|
||||||
word={word}
|
|
||||||
sung={sung}
|
|
||||||
colors={colors}
|
|
||||||
textStyle={textStyle}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function FilledWord({
|
|
||||||
word,
|
|
||||||
sung,
|
|
||||||
colors,
|
|
||||||
textStyle,
|
|
||||||
}: {
|
|
||||||
word: LyricWord
|
|
||||||
sung: SharedValue<number>
|
|
||||||
colors: NowPlayingColors
|
|
||||||
textStyle: { fontSize: number; lineHeight: number }
|
|
||||||
}) {
|
|
||||||
const [width, setWidth] = useState(0)
|
|
||||||
const text = word.text.trim()
|
|
||||||
const wipe = useAnimatedStyle(() => {
|
|
||||||
const progress =
|
|
||||||
(sung.value - word.start) / Math.max(word.end - word.start, 0.05)
|
|
||||||
return { width: width * Math.min(Math.max(progress, 0), 1) }
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
<Text
|
|
||||||
style={[styles.lineText, textStyle, { color: colors.lyricsUnsung }]}
|
|
||||||
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</Text>
|
|
||||||
<Animated.View style={[styles.wipe, wipe]}>
|
|
||||||
<Text
|
|
||||||
numberOfLines={1}
|
|
||||||
style={[
|
|
||||||
styles.lineText,
|
|
||||||
textStyle,
|
|
||||||
{ color: colors.foreground, width },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</Text>
|
|
||||||
</Animated.View>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
fill: { flex: 1 },
|
fill: { flex: 1 },
|
||||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||||
emptyText: { fontSize: 17, fontWeight: "600" },
|
emptyText: { fontSize: 17, fontWeight: "600" },
|
||||||
line: { paddingVertical: 9 },
|
line: { paddingVertical: 9 },
|
||||||
lineText: { fontWeight: "800" },
|
lineText: { fontWeight: "800" },
|
||||||
words: { flexDirection: "row", flexWrap: "wrap" },
|
|
||||||
wipe: {
|
|
||||||
position: "absolute",
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||||
stanzaGap: { height: 18 },
|
stanzaGap: { height: 18 },
|
||||||
})
|
})
|
||||||
@@ -7,7 +7,7 @@ import { MusicEntityView } from "@/components/music-entity-view"
|
|||||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
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,
|
||||||
@@ -302,6 +302,7 @@ export function MediaGridList({
|
|||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
title,
|
title,
|
||||||
|
titleAccessory,
|
||||||
}: {
|
}: {
|
||||||
content: MediaItem[]
|
content: MediaItem[]
|
||||||
paddingBottom: number
|
paddingBottom: number
|
||||||
@@ -310,6 +311,7 @@ export function MediaGridList({
|
|||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
title?: string
|
title?: string
|
||||||
|
titleAccessory?: ReactNode
|
||||||
}) {
|
}) {
|
||||||
const tabletLayout = useTabletLayout()
|
const tabletLayout = useTabletLayout()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||||
@@ -334,6 +336,7 @@ export function MediaGridList({
|
|||||||
ListHeaderComponent={ListHeaderComponent}
|
ListHeaderComponent={ListHeaderComponent}
|
||||||
contentInset={contentInset}
|
contentInset={contentInset}
|
||||||
title={title}
|
title={title}
|
||||||
|
titleAccessory={titleAccessory}
|
||||||
renderCard={renderTabletCard}
|
renderCard={renderTabletCard}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -344,6 +347,7 @@ export function MediaGridList({
|
|||||||
<ScreenTitle
|
<ScreenTitle
|
||||||
title={title}
|
title={title}
|
||||||
scrollY={scrollY}
|
scrollY={scrollY}
|
||||||
|
accessory={titleAccessory}
|
||||||
// Inset grids already pad the whole list horizontally.
|
// Inset grids already pad the whole list horizontally.
|
||||||
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||||
import type { Component } from "react"
|
import type { Component, ReactNode } from "react"
|
||||||
import {
|
import {
|
||||||
Platform,
|
Platform,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
|
Text,
|
||||||
type ScrollViewInstance,
|
type ScrollViewInstance,
|
||||||
type StyleProp,
|
type StyleProp,
|
||||||
type TextStyle,
|
type ViewStyle,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import Animated, {
|
import Animated, {
|
||||||
useAnimatedRef,
|
useAnimatedRef,
|
||||||
@@ -33,17 +34,20 @@ export function useScreenTitleScroll<
|
|||||||
* iOS screen title rendered as the first item of a screen's scroll content,
|
* 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
|
* 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
|
* 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({
|
export function ScreenTitle({
|
||||||
title,
|
title,
|
||||||
scrollY,
|
scrollY,
|
||||||
|
accessory,
|
||||||
style,
|
style,
|
||||||
}: {
|
}: {
|
||||||
title: string
|
title: string
|
||||||
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
||||||
scrollY?: SharedValue<number>
|
scrollY?: SharedValue<number>
|
||||||
style?: StyleProp<TextStyle>
|
accessory?: ReactNode
|
||||||
|
style?: StyleProp<ViewStyle>
|
||||||
}) {
|
}) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
// At rest the scroll offset is minus the automatic header inset, so any
|
// 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
|
if (Platform.OS !== "ios") return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.Text
|
<Animated.View style={[styles.row, style, pinStyle]}>
|
||||||
accessibilityRole="header"
|
<Text
|
||||||
numberOfLines={2}
|
accessibilityRole="header"
|
||||||
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
|
numberOfLines={2}
|
||||||
>
|
style={[styles.title, { color: colors.foreground }]}
|
||||||
{title}
|
>
|
||||||
</Animated.Text>
|
{title}
|
||||||
|
</Text>
|
||||||
|
{accessory}
|
||||||
|
</Animated.View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
title: {
|
row: {
|
||||||
fontSize: 34,
|
flexDirection: "row",
|
||||||
lineHeight: 41,
|
alignItems: "center",
|
||||||
fontWeight: "700",
|
gap: spacing.md,
|
||||||
letterSpacing: 0.37,
|
|
||||||
paddingHorizontal: spacing.lg,
|
paddingHorizontal: spacing.lg,
|
||||||
paddingTop: 3,
|
paddingTop: 3,
|
||||||
paddingBottom: 8,
|
paddingBottom: 8,
|
||||||
},
|
},
|
||||||
|
title: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: 34,
|
||||||
|
lineHeight: 41,
|
||||||
|
fontWeight: "700",
|
||||||
|
letterSpacing: 0.37,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import Animated from "react-native-reanimated"
|
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 { 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"
|
||||||
@@ -86,7 +87,12 @@ function SearchResultsBody({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
return <SongListSkeleton title={title} />
|
return (
|
||||||
|
<SongListSkeleton
|
||||||
|
title={title}
|
||||||
|
titleAccessory={<ProfileHeaderButton />}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -101,7 +107,11 @@ function SearchResultsBody({
|
|||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<>
|
<>
|
||||||
<ScreenTitle title={title} scrollY={scrollY} />
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
scrollY={scrollY}
|
||||||
|
accessory={<ProfileHeaderButton />}
|
||||||
|
/>
|
||||||
{hasQuery && !hasResults ? (
|
{hasQuery && !hasResults ? (
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
<Text
|
<Text
|
||||||
|
|||||||
@@ -155,13 +155,15 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
|||||||
export function SongListSkeleton({
|
export function SongListSkeleton({
|
||||||
rows = 10,
|
rows = 10,
|
||||||
title,
|
title,
|
||||||
|
titleAccessory,
|
||||||
}: {
|
}: {
|
||||||
rows?: number
|
rows?: number
|
||||||
title?: string
|
title?: string
|
||||||
|
titleAccessory?: ReactNode
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
{title ? <ScreenTitle title={title} /> : null}
|
{title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
|
||||||
<SongRows rows={rows} />
|
<SongRows rows={rows} />
|
||||||
</SkeletonScreen>
|
</SkeletonScreen>
|
||||||
)
|
)
|
||||||
@@ -243,6 +245,7 @@ export function MediaGridSkeleton({
|
|||||||
contentInset = true,
|
contentInset = true,
|
||||||
header,
|
header,
|
||||||
title,
|
title,
|
||||||
|
titleAccessory,
|
||||||
}: {
|
}: {
|
||||||
items?: number
|
items?: number
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
@@ -250,6 +253,7 @@ export function MediaGridSkeleton({
|
|||||||
header?: ReactNode
|
header?: ReactNode
|
||||||
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||||
title?: string
|
title?: string
|
||||||
|
titleAccessory?: ReactNode
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
@@ -259,7 +263,7 @@ export function MediaGridSkeleton({
|
|||||||
header={
|
header={
|
||||||
title ? (
|
title ? (
|
||||||
<>
|
<>
|
||||||
<MediaGridTitle title={title} />
|
<MediaGridTitle title={title} accessory={titleAccessory} />
|
||||||
{header}
|
{header}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@@ -271,11 +275,18 @@ export function MediaGridSkeleton({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function MediaGridTitle({ title }: { title: string }) {
|
function MediaGridTitle({
|
||||||
|
title,
|
||||||
|
accessory,
|
||||||
|
}: {
|
||||||
|
title: string
|
||||||
|
accessory?: ReactNode
|
||||||
|
}) {
|
||||||
const { horizontalPadding } = useMediaGridLayout()
|
const { horizontalPadding } = useMediaGridLayout()
|
||||||
return (
|
return (
|
||||||
<ScreenTitle
|
<ScreenTitle
|
||||||
title={title}
|
title={title}
|
||||||
|
accessory={accessory}
|
||||||
style={{ paddingHorizontal: horizontalPadding }}
|
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 (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
<View style={styles.home}>
|
<View style={styles.home}>
|
||||||
<ScreenTitle title={title} style={styles.homeTitle} />
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
accessory={titleAccessory}
|
||||||
|
style={styles.homeTitle}
|
||||||
|
/>
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
type ReactElement,
|
type ReactElement,
|
||||||
|
type ReactNode,
|
||||||
} from "react"
|
} from "react"
|
||||||
import {
|
import {
|
||||||
type ScrollViewInstance,
|
type ScrollViewInstance,
|
||||||
@@ -31,6 +32,7 @@ type GridProps = {
|
|||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
title?: string
|
title?: string
|
||||||
|
titleAccessory?: ReactNode
|
||||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +47,7 @@ export function TabletMediaGrid({
|
|||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
title,
|
title,
|
||||||
|
titleAccessory,
|
||||||
renderCard,
|
renderCard,
|
||||||
}: GridProps) {
|
}: GridProps) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
@@ -126,6 +129,7 @@ export function TabletMediaGrid({
|
|||||||
<ScreenTitle
|
<ScreenTitle
|
||||||
title={title}
|
title={title}
|
||||||
scrollY={titleScrollY}
|
scrollY={titleScrollY}
|
||||||
|
accessory={titleAccessory}
|
||||||
style={{ paddingHorizontal: horizontalPadding }}
|
style={{ paddingHorizontal: horizontalPadding }}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ export const tabStackScreenTitles: Record<string, string> = {
|
|||||||
export const inlineTitleOptions: StackScreenOptions =
|
export const inlineTitleOptions: StackScreenOptions =
|
||||||
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
|
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 {
|
||||||
|
|||||||
@@ -12,26 +12,11 @@ import { cn } from "@/lib/utils"
|
|||||||
import {
|
import {
|
||||||
activeLineIndex,
|
activeLineIndex,
|
||||||
type LyricLine,
|
type LyricLine,
|
||||||
type LyricWord,
|
|
||||||
type Lyrics,
|
type Lyrics,
|
||||||
} from "@otunes/convex/client/lyrics"
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
/** How long a manual scroll keeps the panel from following the song. */
|
/** How long a manual scroll keeps the panel from following the song. */
|
||||||
const MANUAL_SCROLL_HOLD_MS = 3000
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
/** Blur by distance from the playing line; farther lines share the last. */
|
|
||||||
const LINE_BLUR = ["blur-none", "blur-[1px]", "blur-[2px]", "blur-[3px]"]
|
|
||||||
/** Unsung words wipe from dim to bright, soft edge first, as they are sung. */
|
|
||||||
const WORD_FILL = {
|
|
||||||
backgroundImage:
|
|
||||||
"linear-gradient(90deg, var(--foreground) 40%, color-mix(in oklab, var(--foreground) 45%, transparent) 60%)",
|
|
||||||
backgroundSize: "250% 100%",
|
|
||||||
}
|
|
||||||
const WORD_FILL_FRAMES = [
|
|
||||||
{ backgroundPosition: "100% 0" },
|
|
||||||
{ backgroundPosition: "0% 0" },
|
|
||||||
]
|
|
||||||
/** How far a word's fill may drift from playback before it is reset. */
|
|
||||||
const FILL_DRIFT_MS = 80
|
|
||||||
|
|
||||||
/** Lyrics beside the page, in the queue's place. Synced lines follow playback. */
|
/** Lyrics beside the page, in the queue's place. Synced lines follow playback. */
|
||||||
export function LyricsPanel() {
|
export function LyricsPanel() {
|
||||||
@@ -62,42 +47,38 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||||
const active = activeLineIndex(lyrics, time)
|
const active = activeLineIndex(lyrics, time)
|
||||||
const scrollRef = React.useRef<HTMLDivElement>(null)
|
const scrollRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
const manualScrollAt = React.useRef(0)
|
||||||
const synced = lyrics.synced !== "none"
|
const synced = lyrics.synced !== "none"
|
||||||
// While the listener scrolls, lines stay sharp and the panel stays put.
|
|
||||||
const [browsing, setBrowsing] = React.useState(false)
|
|
||||||
const browseTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
||||||
|
|
||||||
React.useEffect(() => () => clearTimeout(browseTimer.current), [])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const container = scrollRef.current
|
const container = scrollRef.current
|
||||||
const line = container?.querySelector<HTMLElement>(
|
const line = container?.querySelector<HTMLElement>(
|
||||||
`[data-line="${Math.max(active, 0)}"]`
|
`[data-line="${Math.max(active, 0)}"]`
|
||||||
)
|
)
|
||||||
if (!container || !line || !synced || browsing) return
|
if (
|
||||||
|
!container ||
|
||||||
|
!line ||
|
||||||
|
!synced ||
|
||||||
|
Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
container.scrollTo({
|
container.scrollTo({
|
||||||
top: line.offsetTop - container.clientHeight * 0.25,
|
top: line.offsetTop - container.clientHeight * 0.25,
|
||||||
behavior: "smooth",
|
behavior: "smooth",
|
||||||
})
|
})
|
||||||
}, [active, synced, browsing])
|
}, [active, synced])
|
||||||
|
|
||||||
const playFrom = React.useCallback(
|
const playFrom = React.useCallback(
|
||||||
(seconds: number) => {
|
(seconds: number) => {
|
||||||
seekTo(seconds)
|
seekTo(seconds)
|
||||||
setIsPlaying(true)
|
setIsPlaying(true)
|
||||||
clearTimeout(browseTimer.current)
|
|
||||||
setBrowsing(false)
|
|
||||||
},
|
},
|
||||||
[seekTo, setIsPlaying]
|
[seekTo, setIsPlaying]
|
||||||
)
|
)
|
||||||
|
|
||||||
const holdScroll = () => {
|
const holdScroll = () => {
|
||||||
setBrowsing(true)
|
manualScrollAt.current = Date.now()
|
||||||
clearTimeout(browseTimer.current)
|
|
||||||
browseTimer.current = setTimeout(
|
|
||||||
() => setBrowsing(false),
|
|
||||||
MANUAL_SCROLL_HOLD_MS
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -105,7 +86,7 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
onWheel={holdScroll}
|
onWheel={holdScroll}
|
||||||
onTouchMove={holdScroll}
|
onTouchMove={holdScroll}
|
||||||
className="group relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
className="relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
||||||
>
|
>
|
||||||
{lyrics.lines.map((line, index) =>
|
{lyrics.lines.map((line, index) =>
|
||||||
synced ? (
|
synced ? (
|
||||||
@@ -113,14 +94,10 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
line={line}
|
line={line}
|
||||||
distance={
|
state={
|
||||||
browsing
|
index === active ? "active" : index < active ? "past" : "next"
|
||||||
? 0
|
|
||||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
|
||||||
}
|
}
|
||||||
active={index === active}
|
|
||||||
time={index === active ? time : null}
|
time={index === active ? time : null}
|
||||||
isPlaying={isPlaying}
|
|
||||||
onSelect={playFrom}
|
onSelect={playFrom}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -140,103 +117,48 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One timed line, blurred by its `distance` from the playing line. Only the
|
* One timed line. Only the active line gets the playback time, so memoized
|
||||||
* active line gets the playback time, so memoized lines elsewhere skip
|
* lines elsewhere skip re-rendering as the song plays.
|
||||||
* re-rendering as the song plays.
|
|
||||||
*/
|
*/
|
||||||
const SyncedLine = React.memo(function SyncedLine({
|
const SyncedLine = React.memo(function SyncedLine({
|
||||||
index,
|
index,
|
||||||
line,
|
line,
|
||||||
distance,
|
state,
|
||||||
active,
|
|
||||||
time,
|
time,
|
||||||
isPlaying,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
}: {
|
}: {
|
||||||
index: number
|
index: number
|
||||||
line: LyricLine
|
line: LyricLine
|
||||||
distance: number
|
state: "past" | "active" | "next"
|
||||||
active: boolean
|
|
||||||
time: number | null
|
time: number | null
|
||||||
isPlaying: boolean
|
|
||||||
onSelect: (seconds: number) => void
|
onSelect: (seconds: number) => void
|
||||||
}) {
|
}) {
|
||||||
|
const active = state === "active"
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-line={index}
|
data-line={index}
|
||||||
onClick={() => onSelect(line.start ?? 0)}
|
onClick={() => onSelect(line.start ?? 0)}
|
||||||
className={cn(
|
className={cn(
|
||||||
"-mx-2 my-1 block w-[calc(100%+1rem)] rounded-md px-2 py-1.5 text-left text-[22px] leading-tight font-bold transition-[color,filter] duration-300 group-hover:blur-none hover:bg-foreground/5",
|
"-mx-2 my-1 block w-[calc(100%+1rem)] rounded-md px-2 py-1.5 text-left text-[22px] leading-tight font-bold transition-colors duration-300 hover:bg-foreground/5",
|
||||||
LINE_BLUR[distance],
|
|
||||||
active && !line.words ? "text-foreground" : "text-foreground/30"
|
active && !line.words ? "text-foreground" : "text-foreground/30"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{active && line.words && time !== null ? (
|
{active && line.words
|
||||||
<FilledWords words={line.words} time={time} isPlaying={isPlaying} />
|
? line.words.map((word, wordIndex) => (
|
||||||
) : (
|
<span
|
||||||
line.text
|
key={wordIndex}
|
||||||
)}
|
className={cn(
|
||||||
|
"transition-colors duration-200",
|
||||||
|
time !== null && time >= word.start
|
||||||
|
? "text-foreground"
|
||||||
|
: "text-foreground/45"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{word.text}
|
||||||
|
</span>
|
||||||
|
))
|
||||||
|
: line.text}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* The playing line's words, each filled as far as it has been sung. The
|
|
||||||
* browser runs the fills; playback updates only correct their drift.
|
|
||||||
*/
|
|
||||||
function FilledWords({
|
|
||||||
words,
|
|
||||||
time,
|
|
||||||
isPlaying,
|
|
||||||
}: {
|
|
||||||
words: LyricWord[]
|
|
||||||
time: number
|
|
||||||
isPlaying: boolean
|
|
||||||
}) {
|
|
||||||
const spans = React.useRef<(HTMLSpanElement | null)[]>([])
|
|
||||||
const fills = React.useRef<(Animation | undefined)[]>([])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
fills.current = words.map((word, index) =>
|
|
||||||
spans.current[index]?.animate(WORD_FILL_FRAMES, {
|
|
||||||
duration: Math.max(word.end - word.start, 0.05) * 1000,
|
|
||||||
easing: "linear",
|
|
||||||
fill: "both",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return () => fills.current.forEach((fill) => fill?.cancel())
|
|
||||||
}, [words])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
fills.current.forEach((fill, index) => {
|
|
||||||
if (!fill) return
|
|
||||||
const at = (time - words[index].start) * 1000
|
|
||||||
if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) {
|
|
||||||
fill.currentTime = at
|
|
||||||
}
|
|
||||||
// `play` on a finished fill would rewind it.
|
|
||||||
const duration = Number(fill.effect?.getTiming().duration ?? 0)
|
|
||||||
if (isPlaying && at < duration) fill.play()
|
|
||||||
else fill.pause()
|
|
||||||
})
|
|
||||||
}, [words, time, isPlaying])
|
|
||||||
|
|
||||||
return words.map((word, index) => {
|
|
||||||
const text = word.text.trimEnd()
|
|
||||||
return (
|
|
||||||
<React.Fragment key={index}>
|
|
||||||
<span
|
|
||||||
ref={(span) => {
|
|
||||||
spans.current[index] = span
|
|
||||||
}}
|
|
||||||
className="bg-clip-text text-transparent"
|
|
||||||
style={WORD_FILL}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</span>
|
|
||||||
{word.text.slice(text.length)}
|
|
||||||
</React.Fragment>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
import { useFavorites } from "@/components/favorites-provider"
|
|
||||||
import type { MediaContextAction } from "@/components/media-context-menu"
|
|
||||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||||
import { usePlayback } from "@/components/playback-provider"
|
import { usePlayback } from "@/components/playback-provider"
|
||||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { Spinner } from "@/components/ui/spinner"
|
import { Spinner } from "@/components/ui/spinner"
|
||||||
import { useMediaActions } from "@/hooks/use-media-actions"
|
|
||||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
||||||
@@ -18,7 +15,6 @@ import {
|
|||||||
moveQueueBlock,
|
moveQueueBlock,
|
||||||
} from "@/lib/move-queue-block"
|
} from "@/lib/move-queue-block"
|
||||||
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
||||||
import { stationArtistId } from "@/lib/station-artist"
|
|
||||||
import { useSongs } from "@/lib/song-cache"
|
import { useSongs } from "@/lib/song-cache"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -185,66 +181,8 @@ export function QueuePanel() {
|
|||||||
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
||||||
[selectableQueue]
|
[selectableQueue]
|
||||||
)
|
)
|
||||||
const {
|
const { selectedIds, handleSelect, handlePointerDown } =
|
||||||
selectedIds,
|
useTrackSelection(selectionItems)
|
||||||
selectedCount,
|
|
||||||
handleSelect,
|
|
||||||
handlePointerDown,
|
|
||||||
prepareContextMenu,
|
|
||||||
clearSelection,
|
|
||||||
} = useTrackSelection(selectionItems)
|
|
||||||
const { isSongFavorite } = useFavorites()
|
|
||||||
const { runSongsAction } = useMediaActions()
|
|
||||||
|
|
||||||
/** The rows a menu acts on: the selection, else just the clicked row. */
|
|
||||||
const menuTargets = React.useCallback(
|
|
||||||
(selectionId: string) => {
|
|
||||||
const ids = selectedIds.has(selectionId)
|
|
||||||
? selectedIds
|
|
||||||
: new Set([selectionId])
|
|
||||||
return selectableQueue.filter((item) => ids.has(item.selectionId))
|
|
||||||
},
|
|
||||||
[selectableQueue, selectedIds]
|
|
||||||
)
|
|
||||||
|
|
||||||
const selectedStationArtistId = React.useMemo(
|
|
||||||
() =>
|
|
||||||
stationArtistId(
|
|
||||||
selectableQueue.flatMap((item) =>
|
|
||||||
item.song ? [{ id: item.selectionId, artist: item.song.artist }] : []
|
|
||||||
),
|
|
||||||
selectedIds
|
|
||||||
),
|
|
||||||
[selectableQueue, selectedIds]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleMediaAction = React.useCallback(
|
|
||||||
(action: MediaContextAction, selectionId: string) => {
|
|
||||||
const songs = menuTargets(selectionId).flatMap((item) =>
|
|
||||||
item.song ? [item.song] : []
|
|
||||||
)
|
|
||||||
const artistId = songs[0]?.artist.id
|
|
||||||
runSongsAction(
|
|
||||||
action,
|
|
||||||
songs.map((song) => song.id),
|
|
||||||
songs.every((song) => song.artist.id === artistId)
|
|
||||||
? artistId
|
|
||||||
: undefined
|
|
||||||
)
|
|
||||||
},
|
|
||||||
[menuTargets, runSongsAction]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleRemove = React.useCallback(
|
|
||||||
(selectionId: string) => {
|
|
||||||
const removed = new Set(
|
|
||||||
menuTargets(selectionId).map((item) => item.queueIndex)
|
|
||||||
)
|
|
||||||
clearSelection()
|
|
||||||
void reorderQueue(queueSongIds.filter((_, index) => !removed.has(index)))
|
|
||||||
},
|
|
||||||
[clearSelection, menuTargets, queueSongIds, reorderQueue]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleRowSelect = React.useCallback(
|
const handleRowSelect = React.useCallback(
|
||||||
(index: number, event: React.MouseEvent) => {
|
(index: number, event: React.MouseEvent) => {
|
||||||
@@ -398,11 +336,6 @@ export function QueuePanel() {
|
|||||||
variant="queue"
|
variant="queue"
|
||||||
song={item.song}
|
song={item.song}
|
||||||
index={index}
|
index={index}
|
||||||
selectionId={item.selectionId}
|
|
||||||
isFavorite={isSongFavorite(item.song.id)}
|
|
||||||
selectedCount={selectedCount}
|
|
||||||
selectionStationArtistId={selectedStationArtistId}
|
|
||||||
removeLabel="Remove from Queue"
|
|
||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
isDragging={draggingIndices.has(index)}
|
isDragging={draggingIndices.has(index)}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
@@ -410,9 +343,6 @@ export function QueuePanel() {
|
|||||||
onPlay={handleRowPlay}
|
onPlay={handleRowPlay}
|
||||||
onDragStart={setDragIndex}
|
onDragStart={setDragIndex}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
onPrepareContextMenu={prepareContextMenu}
|
|
||||||
onMediaAction={handleMediaAction}
|
|
||||||
onRemove={handleRemove}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<QueueSongRowSkeleton key={item.selectionId} />
|
<QueueSongRowSkeleton key={item.selectionId} />
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
|||||||
* columns (use with `LibraryTrackListHeader`).
|
* columns (use with `LibraryTrackListHeader`).
|
||||||
* - `album`: favorite star, track number, title with optional credits.
|
* - `album`: favorite star, track number, title with optional credits.
|
||||||
* - `playlist`: cover with favorite overlay, track number, title.
|
* - `playlist`: cover with favorite overlay, track number, title.
|
||||||
* - `queue`: cover, title and artist, duration, and a reorder grip.
|
* - `queue`: cover, title and artist, duration, and a reorder grip. No menu.
|
||||||
*/
|
*/
|
||||||
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
||||||
|
|
||||||
@@ -47,12 +47,6 @@ export type TrackRowProps = {
|
|||||||
song: BrowseSong
|
song: BrowseSong
|
||||||
/** Position in the list the selection hook was given. */
|
/** Position in the list the selection hook was given. */
|
||||||
index: number
|
index: number
|
||||||
/**
|
|
||||||
* The id the selection hook knows this row by, passed to the menu and
|
|
||||||
* remove callbacks. Defaults to the song id; the queue uses a per-position
|
|
||||||
* id since a song can appear more than once.
|
|
||||||
*/
|
|
||||||
selectionId?: string
|
|
||||||
/** Number shown in the track number column (`album` and `playlist`). */
|
/** Number shown in the track number column (`album` and `playlist`). */
|
||||||
trackNumber?: number
|
trackNumber?: number
|
||||||
/** Secondary line under the title, e.g. album track credits. */
|
/** Secondary line under the title, e.g. album track credits. */
|
||||||
@@ -77,10 +71,10 @@ export type TrackRowProps = {
|
|||||||
onPointerDown: (event: React.MouseEvent) => void
|
onPointerDown: (event: React.MouseEvent) => void
|
||||||
onPlay: (index: number) => void
|
onPlay: (index: number) => void
|
||||||
onToggleFavorite?: (songId: string) => void
|
onToggleFavorite?: (songId: string) => void
|
||||||
onPrepareContextMenu?: (selectionId: string) => void
|
onPrepareContextMenu?: (songId: string) => void
|
||||||
/** Renders the "more options" and right-click menus when provided. */
|
/** Renders the "more options" and right-click menus when provided. */
|
||||||
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
|
onMediaAction?: (action: MediaContextAction, songId: string) => void
|
||||||
onRemove?: (selectionId: string) => void
|
onRemove?: (songId: string) => void
|
||||||
/** Makes the row draggable when provided. */
|
/** Makes the row draggable when provided. */
|
||||||
onDragStart?: (index: number) => void
|
onDragStart?: (index: number) => void
|
||||||
onDrop?: (index: number) => void
|
onDrop?: (index: number) => void
|
||||||
@@ -257,7 +251,6 @@ function TrackRowComponent({
|
|||||||
variant,
|
variant,
|
||||||
song,
|
song,
|
||||||
index,
|
index,
|
||||||
selectionId,
|
|
||||||
trackNumber,
|
trackNumber,
|
||||||
subtitle,
|
subtitle,
|
||||||
downloadCollection,
|
downloadCollection,
|
||||||
@@ -291,7 +284,6 @@ function TrackRowComponent({
|
|||||||
const flush = variant === "library" || variant === "queue"
|
const flush = variant === "library" || variant === "queue"
|
||||||
const play = () => onPlay(index)
|
const play = () => onPlay(index)
|
||||||
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
||||||
const rowId = selectionId ?? song.id
|
|
||||||
|
|
||||||
const favoriteStar = (
|
const favoriteStar = (
|
||||||
<div className="flex shrink-0 items-center justify-center">
|
<div className="flex shrink-0 items-center justify-center">
|
||||||
@@ -341,8 +333,8 @@ function TrackRowComponent({
|
|||||||
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
||||||
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
||||||
inSelectionRange: inRange,
|
inSelectionRange: inRange,
|
||||||
onOpenMenu: () => onPrepareContextMenu?.(rowId),
|
onOpenMenu: () => onPrepareContextMenu?.(song.id),
|
||||||
onAction: (action) => onMediaAction(action, rowId),
|
onAction: (action) => onMediaAction(action, song.id),
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite: showFavoriteInMenu,
|
showFavorite: showFavoriteInMenu,
|
||||||
favorited: isFavorite,
|
favorited: isFavorite,
|
||||||
@@ -359,7 +351,7 @@ function TrackRowComponent({
|
|||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onRemove(rowId)}
|
onClick={() => onRemove(song.id)}
|
||||||
>
|
>
|
||||||
{removeLabel}
|
{removeLabel}
|
||||||
<Trash2 />
|
<Trash2 />
|
||||||
@@ -563,7 +555,7 @@ function TrackRowComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass stable callbacks: they receive the row's `index`, song id or
|
* Pass stable callbacks: they receive the row's `index` or song id, so one
|
||||||
* `selectionId`, so one handler can serve every row.
|
* handler can serve every row.
|
||||||
*/
|
*/
|
||||||
export const TrackRow = React.memo(TrackRowComponent)
|
export const TrackRow = React.memo(TrackRowComponent)
|
||||||
Reference in new issue
Block a user