import { Image } from 'expo-image'; import { Linking, Pressable, Share, StyleSheet, Text, View } from 'react-native'; import { SERVICE_LABELS, STREAMING_SERVICES, openUrl, shareText, trackUrl, type StreamingService, type TrackDTO } from '@musicshare/shared'; import { WEB_URL } from '@/lib/config'; import { useSession } from '@/lib/session'; import { showError } from '@/lib/errors'; import { colors, fonts, radius, space } from '@/lib/theme'; import { Button } from './ui'; /** * Links are https universal/app links, so Linking.openURL hands them to the * native Spotify / Apple Music / YouTube Music app when it's installed. */ const open = (url: string) => Linking.openURL(url).catch((e) => showError(e, "Couldn't open link")); /** The phone's share sheet, with a link to the song's page (which opens it in any service). */ function shareTrack(track: TrackDTO, from: string | undefined) { const url = trackUrl(WEB_URL, track.id, from); // Android shows only `message`; iOS shows `url` as a rich link next to it. Share.share({ message: `${shareText(track)} ${url}`, url, title: shareText(track) }).catch((e) => showError(e, "Couldn't share")); } export function TrackCard({ track, preferred }: { track: TrackDTO; preferred: StreamingService | null | undefined }) { const { me } = useSession(); const primary = preferred ? openUrl(track, preferred) : null; const others = STREAMING_SERVICES.filter((s) => s !== preferred); return ( {track.artworkUrl ? ( ) : ( ♪ )} {track.title} {track.artist} {track.album ? · {track.album} : null} {preferred && primary && (