Compare commits
2
Commits
No files matched your search
@@ -489,8 +489,21 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
|||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
}) {
|
}) {
|
||||||
const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable
|
const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable
|
||||||
|
const { config } = useServerConfig()
|
||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
|
preview={
|
||||||
|
config
|
||||||
|
? {
|
||||||
|
kind: "song",
|
||||||
|
title: track.title,
|
||||||
|
artist: album.artist.name,
|
||||||
|
album: album.title,
|
||||||
|
artworkUrl: albumCoverUrl(config.serverUrl, album.id),
|
||||||
|
hasArtwork: album.cover != null,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
stationArtistId={album.artist.id}
|
stationArtistId={album.artist.id}
|
||||||
favorited={favorited}
|
favorited={favorited}
|
||||||
navigation={{
|
navigation={{
|
||||||
|
|||||||
@@ -141,6 +141,12 @@ const ArtistRow = memo(function ArtistRow({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
|
preview={{
|
||||||
|
kind: "artist",
|
||||||
|
title: artist.name,
|
||||||
|
artworkUrl: artistCoverUrl(serverUrl, artist.id),
|
||||||
|
hasArtwork: artist.photo != null,
|
||||||
|
}}
|
||||||
favorited={favorited}
|
favorited={favorited}
|
||||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||||
onAction={(action) => void onAction(artist, action)}
|
onAction={(action) => void onAction(artist, action)}
|
||||||
@@ -160,7 +166,11 @@ const ArtistRow = memo(function ArtistRow({
|
|||||||
>
|
>
|
||||||
{artist.name}
|
{artist.name}
|
||||||
</Text>
|
</Text>
|
||||||
<Ionicons name="chevron-forward" size={16} color={colors.mutedForeground} />
|
<Ionicons
|
||||||
|
name="chevron-forward"
|
||||||
|
size={16}
|
||||||
|
color={colors.mutedForeground}
|
||||||
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</MediaContextMenu>
|
</MediaContextMenu>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ export const AlbumCard = memo(function AlbumCard({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
|
preview={{
|
||||||
|
kind: "album",
|
||||||
|
title: album.title,
|
||||||
|
artist: album.artist.name,
|
||||||
|
artworkUrl: albumCoverUrl(config.serverUrl, album.id),
|
||||||
|
hasArtwork: album.cover != null,
|
||||||
|
}}
|
||||||
favorited={isAlbumFavorite(album.id)}
|
favorited={isAlbumFavorite(album.id)}
|
||||||
stationArtistId={album.artist.id}
|
stationArtistId={album.artist.id}
|
||||||
navigation={{ artist: { id: album.artist.id } }}
|
navigation={{ artist: { id: album.artist.id } }}
|
||||||
@@ -149,6 +156,12 @@ export const ArtistCard = memo(function ArtistCard({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
|
preview={{
|
||||||
|
kind: "artist",
|
||||||
|
title: artist.name,
|
||||||
|
artworkUrl: artistCoverUrl(config.serverUrl, artist.id),
|
||||||
|
hasArtwork: artist.photo != null,
|
||||||
|
}}
|
||||||
favorited={isArtistFavorite(artist.id)}
|
favorited={isArtistFavorite(artist.id)}
|
||||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||||
onAction={(action) => void handleArtistAction(artist, action)}
|
onAction={(action) => void handleArtistAction(artist, action)}
|
||||||
|
|||||||
@@ -4,12 +4,19 @@ import { requireNativeView } from "expo"
|
|||||||
import type { ComponentType, ReactNode } from "react"
|
import type { ComponentType, ReactNode } from "react"
|
||||||
import {
|
import {
|
||||||
Platform,
|
Platform,
|
||||||
|
Text,
|
||||||
|
useWindowDimensions,
|
||||||
View,
|
View,
|
||||||
type StyleProp,
|
type StyleProp,
|
||||||
type ViewProps,
|
type ViewProps,
|
||||||
type ViewStyle,
|
type ViewStyle,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
|
||||||
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
|
import { CoverImage } from "@/components/cover-image"
|
||||||
|
import { useThemeColors } from "@/lib/theme"
|
||||||
|
import { useAppNavigation } from "@/lib/app-navigation"
|
||||||
|
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import type { MediaShareContext } from "@/lib/media-links"
|
import type { MediaShareContext } from "@/lib/media-links"
|
||||||
import { shouldShowShare } from "@/lib/media-links"
|
import { shouldShowShare } from "@/lib/media-links"
|
||||||
@@ -32,7 +39,17 @@ export type MediaNavigation = {
|
|||||||
album?: { id: string }
|
album?: { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type MediaMenuPreview = {
|
||||||
|
title: string
|
||||||
|
artist?: string
|
||||||
|
album?: string
|
||||||
|
artworkUrl: string
|
||||||
|
hasArtwork: boolean
|
||||||
|
kind: "album" | "artist" | "song"
|
||||||
|
}
|
||||||
|
|
||||||
export type MediaMenuConfig = {
|
export type MediaMenuConfig = {
|
||||||
|
preview?: MediaMenuPreview
|
||||||
selectedCount?: number
|
selectedCount?: number
|
||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
@@ -214,10 +231,95 @@ function MediaMenuBase({
|
|||||||
const NativeContextMenuView =
|
const NativeContextMenuView =
|
||||||
Platform.OS === "ios"
|
Platform.OS === "ios"
|
||||||
? requireNativeView<
|
? requireNativeView<
|
||||||
ViewProps & { disableForceFlatten?: boolean; children: ReactNode }
|
ViewProps & {
|
||||||
|
disableForceFlatten?: boolean
|
||||||
|
children: ReactNode
|
||||||
|
onPreviewTappedAnimationCompleted?: () => void
|
||||||
|
}
|
||||||
>("ExpoRouterNativeLinkPreview", "NativeLinkPreviewView")
|
>("ExpoRouterNativeLinkPreview", "NativeLinkPreviewView")
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
const NativeContextMenuPreview =
|
||||||
|
Platform.OS === "ios"
|
||||||
|
? requireNativeView<
|
||||||
|
ViewProps & {
|
||||||
|
preferredContentSize: { width: number; height: number }
|
||||||
|
children: ReactNode
|
||||||
|
}
|
||||||
|
>("ExpoRouterNativeLinkPreview", "NativeLinkPreviewContentView")
|
||||||
|
: null
|
||||||
|
|
||||||
|
function MediaPreview({ preview }: { preview: MediaMenuPreview }) {
|
||||||
|
const colors = useThemeColors()
|
||||||
|
const { width: windowWidth, fontScale } = useWindowDimensions()
|
||||||
|
if (!NativeContextMenuPreview) return null
|
||||||
|
|
||||||
|
const width = Math.min(360, windowWidth - 32)
|
||||||
|
const height = Math.max(124, 32 + 76 * fontScale)
|
||||||
|
const isArtist = preview.kind === "artist"
|
||||||
|
return (
|
||||||
|
// Match Expo Router's preview wrapper: UIKit mounts this separately, but
|
||||||
|
// Yoga must also keep it out of the trigger's normal layout.
|
||||||
|
<NativeContextMenuPreview
|
||||||
|
preferredContentSize={{ width, height }}
|
||||||
|
style={{ position: "absolute", top: 0, left: 0 }}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
padding: 16,
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 16,
|
||||||
|
backgroundColor: colors.card,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CoverImage
|
||||||
|
uri={preview.artworkUrl}
|
||||||
|
hasCover={preview.hasArtwork}
|
||||||
|
style={{ width: 88, height: 88, borderRadius: isArtist ? 44 : 12 }}
|
||||||
|
/>
|
||||||
|
<View style={{ flex: 1, gap: 2 }}>
|
||||||
|
<Text
|
||||||
|
numberOfLines={2}
|
||||||
|
style={{
|
||||||
|
color: colors.foreground,
|
||||||
|
fontSize: 17,
|
||||||
|
fontWeight: "600",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{preview.title}
|
||||||
|
</Text>
|
||||||
|
{preview.artist ? (
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{ color: colors.mutedForeground, fontSize: 15 }}
|
||||||
|
>
|
||||||
|
{preview.artist}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
{preview.album ? (
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{ color: colors.mutedForeground, fontSize: 14 }}
|
||||||
|
>
|
||||||
|
{preview.album}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
{preview.kind !== "song" ? (
|
||||||
|
<Ionicons
|
||||||
|
name="chevron-forward"
|
||||||
|
size={20}
|
||||||
|
color={colors.mutedForeground}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
</NativeContextMenuPreview>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const NativeContextMenuAction: ComponentType<{
|
const NativeContextMenuAction: ComponentType<{
|
||||||
identifier: string
|
identifier: string
|
||||||
title: string
|
title: string
|
||||||
@@ -233,11 +335,13 @@ const NativeContextMenuAction: ComponentType<{
|
|||||||
|
|
||||||
function NativeMediaContextMenu({
|
function NativeMediaContextMenu({
|
||||||
children,
|
children,
|
||||||
|
preview,
|
||||||
onAction,
|
onAction,
|
||||||
share,
|
share,
|
||||||
...actionConfig
|
...actionConfig
|
||||||
}: MediaMenuWrapperProps) {
|
}: MediaMenuWrapperProps) {
|
||||||
const { config } = useServerConfig()
|
const { config } = useServerConfig()
|
||||||
|
const { push } = useAppNavigation()
|
||||||
|
|
||||||
if (!NativeContextMenuView || !NativeContextMenuAction) {
|
if (!NativeContextMenuView || !NativeContextMenuAction) {
|
||||||
return children
|
return children
|
||||||
@@ -252,10 +356,21 @@ function NativeMediaContextMenu({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NativeContextMenuView style={{ display: "contents" }} disableForceFlatten>
|
<NativeContextMenuView
|
||||||
|
style={{ display: "contents" }}
|
||||||
|
disableForceFlatten
|
||||||
|
onPreviewTappedAnimationCompleted={() => {
|
||||||
|
if (share?.type === "artist") push(`/artist/${share.artistId}`)
|
||||||
|
else if (share?.type === "album" || share?.type === "song")
|
||||||
|
push(`/album/${share.albumId}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* The native menu retains its first trigger. Keep that view mounted when
|
{/* The native menu retains its first trigger. Keep that view mounted when
|
||||||
focus changes replace the Siri entity wrapper inside it. */}
|
focus changes replace the Siri entity wrapper inside it. */}
|
||||||
<View collapsable={false}>{children}</View>
|
<View collapsable={false}>{children}</View>
|
||||||
|
{preview && (actionConfig.selectedCount ?? 1) === 1 ? (
|
||||||
|
<MediaPreview preview={preview} />
|
||||||
|
) : null}
|
||||||
{buildMediaMenuActions({ ...actionConfig, share }).map((action) => (
|
{buildMediaMenuActions({ ...actionConfig, share }).map((action) => (
|
||||||
<NativeContextMenuAction
|
<NativeContextMenuAction
|
||||||
key={action.id}
|
key={action.id}
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ export const SongListRow = memo(function SongListRow({
|
|||||||
onPlay: (song: BrowseSong) => void
|
onPlay: (song: BrowseSong) => void
|
||||||
onAction: (song: BrowseSong, action: MediaAction) => void
|
onAction: (song: BrowseSong, action: MediaAction) => void
|
||||||
}) {
|
}) {
|
||||||
|
const { config } = useServerConfig()
|
||||||
const handlePress = useCallback(() => onPlay(song), [onPlay, song])
|
const handlePress = useCallback(() => onPlay(song), [onPlay, song])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -182,6 +183,16 @@ export const SongListRow = memo(function SongListRow({
|
|||||||
swipe={swipe}
|
swipe={swipe}
|
||||||
onPress={handlePress}
|
onPress={handlePress}
|
||||||
contextMenu={{
|
contextMenu={{
|
||||||
|
preview: config
|
||||||
|
? {
|
||||||
|
kind: "song",
|
||||||
|
title: song.title,
|
||||||
|
artist: song.artist.name,
|
||||||
|
album: song.album.title,
|
||||||
|
artworkUrl: albumCoverUrl(config.serverUrl, song.album.id),
|
||||||
|
hasArtwork: song.album.cover != null,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
stationArtistId: song.artist.id,
|
stationArtistId: song.artist.id,
|
||||||
favorited,
|
favorited,
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
|
|||||||
Reference in new issue
Block a user