Compare commits

..
7 changed files with 83 additions and 101 deletions

No files matched your search

+12 -7
View File
@@ -12,6 +12,7 @@ import Animated, {
Easing,
useAnimatedStyle,
useSharedValue,
withSequence,
withTiming,
type SharedValue,
} from "react-native-reanimated"
@@ -284,13 +285,17 @@ function FilledWords({
useEffect(() => {
cancelAnimation(sung)
sung.value = time
if (isPlaying && end > time) {
sung.value = withTiming(end, {
duration: (end - time) * 1000,
easing: Easing.linear,
})
}
// Jump to the reported time first, so the wipe never runs from a stale one.
sung.value =
isPlaying && end > time
? withSequence(
withTiming(time, { duration: 0 }),
withTiming(end, {
duration: (end - time) * 1000,
easing: Easing.linear,
})
)
: time
}, [sung, time, isPlaying, end])
return (
@@ -0,0 +1,3 @@
{
"platforms": ["apple"]
}
@@ -0,0 +1,37 @@
// React Native draws `filter: [{ blur }]` on iOS only with its SwiftUI
// filters flag, which the stable release leaves off. This keeps the stable
// flags and turns that one on.
#import <UIKit/UIKit.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>
using namespace facebook::react;
class SwiftUIFilterFlags : public ReactNativeFeatureFlagsOverridesOSSStable {
public:
bool enableSwiftUIBasedFilters() override {
return true;
}
};
@interface SwiftUIFilters : NSObject
@end
@implementation SwiftUIFilters
+ (void)load
{
// React Native sets its flags once while launching and throws if they were
// set first, so this waits for launch to finish. No views exist yet then.
[NSNotificationCenter.defaultCenter
addObserverForName:UIApplicationDidFinishLaunchingNotification
object:nil
queue:nil
usingBlock:^(NSNotification *notification) {
ReactNativeFeatureFlags::dangerouslyForceOverride(
std::make_unique<SwiftUIFilterFlags>());
}];
}
@end
@@ -0,0 +1,14 @@
Pod::Spec.new do |s|
s.name = 'SwiftUIFilters'
s.version = '1.0.0'
s.summary = 'Turns on React Native view filters like blur on iOS'
s.description = s.summary
s.license = { :type => 'MIT' }
s.author = 'oTunes'
s.homepage = 'https://otunes.abunchofknowitalls.com'
s.platforms = { :ios => '16.4' }
s.source = { :git => '' }
s.static_framework = true
install_modules_dependencies(s)
s.source_files = '**/*.{h,mm}'
end
+6 -5
View File
@@ -183,7 +183,8 @@ const SyncedLine = React.memo(function SyncedLine({
/**
* 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.
* browser runs the fills on the song's timeline (a word's start is its
* delay); playback updates only correct their drift.
*/
function FilledWords({
words,
@@ -200,6 +201,7 @@ function FilledWords({
React.useEffect(() => {
fills.current = words.map((word, index) =>
spans.current[index]?.animate(WORD_FILL_FRAMES, {
delay: word.start * 1000,
duration: Math.max(word.end - word.start, 0.05) * 1000,
easing: "linear",
fill: "both",
@@ -209,15 +211,14 @@ function FilledWords({
}, [words])
React.useEffect(() => {
const at = time * 1000
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()
// `play` on a finished fill would rewind it to the start.
if (isPlaying && time < words[index].end) fill.play()
else fill.pause()
})
}, [words, time, isPlaying])
+2 -72
View File
@@ -2,14 +2,11 @@
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 { usePlayback } from "@/components/playback-provider"
import { TrackCover, TrackRow } from "@/components/track-row"
import { Skeleton } from "@/components/ui/skeleton"
import { Spinner } from "@/components/ui/spinner"
import { useMediaActions } from "@/hooks/use-media-actions"
import { useTrackSelection } from "@/hooks/use-track-selection"
import type { Id } from "@otunes/convex/_generated/dataModel"
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
@@ -18,7 +15,6 @@ import {
moveQueueBlock,
} from "@/lib/move-queue-block"
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
import { stationArtistId } from "@/lib/station-artist"
import { useSongs } from "@/lib/song-cache"
import { cn } from "@/lib/utils"
@@ -185,66 +181,8 @@ export function QueuePanel() {
() => selectableQueue.map((item) => ({ id: item.selectionId })),
[selectableQueue]
)
const {
selectedIds,
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 { selectedIds, handleSelect, handlePointerDown } =
useTrackSelection(selectionItems)
const handleRowSelect = React.useCallback(
(index: number, event: React.MouseEvent) => {
@@ -398,11 +336,6 @@ export function QueuePanel() {
variant="queue"
song={item.song}
index={index}
selectionId={item.selectionId}
isFavorite={isSongFavorite(item.song.id)}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
removeLabel="Remove from Queue"
selectionPosition={selectionPositions[index]}
isDragging={draggingIndices.has(index)}
onPointerDown={handlePointerDown}
@@ -410,9 +343,6 @@ export function QueuePanel() {
onPlay={handleRowPlay}
onDragStart={setDragIndex}
onDrop={handleDrop}
onPrepareContextMenu={prepareContextMenu}
onMediaAction={handleMediaAction}
onRemove={handleRemove}
/>
) : (
<QueueSongRowSkeleton key={item.selectionId} />
+9 -17
View File
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
* columns (use with `LibraryTrackListHeader`).
* - `album`: favorite star, track number, title with optional credits.
* - `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"
@@ -47,12 +47,6 @@ export type TrackRowProps = {
song: BrowseSong
/** Position in the list the selection hook was given. */
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`). */
trackNumber?: number
/** Secondary line under the title, e.g. album track credits. */
@@ -77,10 +71,10 @@ export type TrackRowProps = {
onPointerDown: (event: React.MouseEvent) => void
onPlay: (index: number) => void
onToggleFavorite?: (songId: string) => void
onPrepareContextMenu?: (selectionId: string) => void
onPrepareContextMenu?: (songId: string) => void
/** Renders the "more options" and right-click menus when provided. */
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
onRemove?: (selectionId: string) => void
onMediaAction?: (action: MediaContextAction, songId: string) => void
onRemove?: (songId: string) => void
/** Makes the row draggable when provided. */
onDragStart?: (index: number) => void
onDrop?: (index: number) => void
@@ -257,7 +251,6 @@ function TrackRowComponent({
variant,
song,
index,
selectionId,
trackNumber,
subtitle,
downloadCollection,
@@ -291,7 +284,6 @@ function TrackRowComponent({
const flush = variant === "library" || variant === "queue"
const play = () => onPlay(index)
const toggleFavorite = () => onToggleFavorite?.(song.id)
const rowId = selectionId ?? song.id
const favoriteStar = (
<div className="flex shrink-0 items-center justify-center">
@@ -341,8 +333,8 @@ function TrackRowComponent({
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
inSelectionRange: inRange,
onOpenMenu: () => onPrepareContextMenu?.(rowId),
onAction: (action) => onMediaAction(action, rowId),
onOpenMenu: () => onPrepareContextMenu?.(song.id),
onAction: (action) => onMediaAction(action, song.id),
playlistLabel,
showFavorite: showFavoriteInMenu,
favorited: isFavorite,
@@ -359,7 +351,7 @@ function TrackRowComponent({
<MediaMenuItem
variant="destructive"
className="justify-between"
onClick={() => onRemove(rowId)}
onClick={() => onRemove(song.id)}
>
{removeLabel}
<Trash2 />
@@ -563,7 +555,7 @@ function TrackRowComponent({
}
/**
* Pass stable callbacks: they receive the row's `index`, song id or
* `selectionId`, so one handler can serve every row.
* Pass stable callbacks: they receive the row's `index` or song id, so one
* handler can serve every row.
*/
export const TrackRow = React.memo(TrackRowComponent)