# Conflicts: # apps/mobile/app/(app)/(tabs)/home/album/[id].tsx # apps/mobile/app/(app)/(tabs)/home/settings.tsx # apps/mobile/hooks/use-cover-palette.ts # apps/mobile/hooks/use-legacy-cover-palette.ts
103 lines
2.3 KiB
TypeScript
103 lines
2.3 KiB
TypeScript
import { StyleSheet, Text, View } from "react-native"
|
|
import Svg, { G, Path } from "react-native-svg"
|
|
|
|
import {
|
|
DOLBY_PATHS,
|
|
DOLBY_VIEW_BOX,
|
|
DOLBY_WIDTH,
|
|
LOSSLESS_FALL,
|
|
LOSSLESS_FALL_GAP,
|
|
LOSSLESS_PEAKS,
|
|
LOSSLESS_STROKES,
|
|
LOSSLESS_THIN_WIDTH,
|
|
LOSSLESS_VIEW_BOX,
|
|
LOSSLESS_WIDTH,
|
|
MARK_HEIGHT,
|
|
} from "@otunes/convex/client/audio-format-marks"
|
|
import type { PlaybackFormat } from "@otunes/convex/playback-stream"
|
|
|
|
const LABEL_SIZE = 13
|
|
|
|
function DolbyMark({ color }: { color: string }) {
|
|
return (
|
|
<Svg width={DOLBY_WIDTH} height={MARK_HEIGHT} viewBox={DOLBY_VIEW_BOX}>
|
|
{DOLBY_PATHS.map((d) => (
|
|
<Path key={d} d={d} fill={color} />
|
|
))}
|
|
</Svg>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Three overlapping waves. Each thick downstroke is outlined in the
|
|
* background color so it reads as passing over the strokes behind it.
|
|
*/
|
|
function LosslessMark({
|
|
color,
|
|
backgroundColor,
|
|
}: {
|
|
color: string
|
|
backgroundColor: string
|
|
}) {
|
|
return (
|
|
<Svg
|
|
width={LOSSLESS_WIDTH}
|
|
height={MARK_HEIGHT}
|
|
viewBox={LOSSLESS_VIEW_BOX}
|
|
>
|
|
{LOSSLESS_STROKES.map(([peak, d], index) => (
|
|
<Path
|
|
key={index}
|
|
d={d}
|
|
x={peak}
|
|
stroke={color}
|
|
strokeWidth={LOSSLESS_THIN_WIDTH}
|
|
strokeLinecap="round"
|
|
fill="none"
|
|
/>
|
|
))}
|
|
{LOSSLESS_PEAKS.map((peak) => (
|
|
<G key={peak} x={peak}>
|
|
<Path d={LOSSLESS_FALL_GAP} fill={backgroundColor} />
|
|
<Path d={LOSSLESS_FALL} fill={color} />
|
|
</G>
|
|
))}
|
|
</Svg>
|
|
)
|
|
}
|
|
|
|
/** The Dolby Atmos or Lossless label shown under the progress bar. */
|
|
export function AudioFormatBadge({
|
|
format,
|
|
color,
|
|
backgroundColor,
|
|
}: {
|
|
format: PlaybackFormat
|
|
color: string
|
|
backgroundColor: string
|
|
}) {
|
|
const label = format === "atmos" ? "Dolby Atmos" : "Lossless"
|
|
return (
|
|
<View style={styles.badge} accessibilityLabel={label}>
|
|
{format === "atmos" ? (
|
|
<DolbyMark color={color} />
|
|
) : (
|
|
<LosslessMark color={color} backgroundColor={backgroundColor} />
|
|
)}
|
|
<Text style={[styles.label, { color }]}>{label}</Text>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
badge: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 3,
|
|
},
|
|
label: {
|
|
fontSize: LABEL_SIZE,
|
|
fontWeight: "500",
|
|
},
|
|
})
|