UIPackage React Native
Search

Playback Queue

Playback queue with caller-composed media rows, current media, and visible reorder and remove controls.

Install

First install? Set up the registry in your app.

npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add playback-queue

Source files

Expand a file to read the source the installer copies into your app.

components/blocks/playback-queue/PlaybackQueue.tsx
import { Children, Fragment, isValidElement, type ReactNode } from 'react'
import { View, type ViewProps } from 'react-native'
import { Ellipsis, Play } from 'lucide-react-native'
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { Icon } from '@/components/ui/icon'
import {
  List,
  ListItem,
  ListItemContent,
  ListItemDescription,
  ListItemTitle,
  ListSeparator,
} from '@/components/ui/list'
import { Text } from '@/components/ui/text'
import { cn } from '@/lib/utils'

export interface PlaybackQueueProps extends ViewProps {
  className?: string
  /** A bounded set of upcoming rows. The queue renders inline and does not virtualize its children. */
  children?: ReactNode
  /** A summary of current media or the caller's player. */
  current?: ReactNode
  actions?: ReactNode
  currentLabel?: string
  upcomingLabel?: string
  emptyMessage?: string
}

/** Shows the current media and caller-composed upcoming items. Playback and ordering stay with the caller. */
export function PlaybackQueue({
  current,
  actions,
  currentLabel = 'Now playing',
  upcomingLabel = 'Up next',
  emptyMessage = 'Your queue is empty. Add something to play next.',
  children,
  className,
  ...props
}: PlaybackQueueProps) {
  const items = Children.toArray(children)

  return (
    <View {...props} className={cn('gap-[20px]', className)}>
      {current ? (
        <View className="gap-[8px]">
          <Text size="sm" variant="muted" className="font-medium">
            {currentLabel}
          </Text>
          {current}
        </View>
      ) : null}
      <View className="gap-[8px]">
        <Text className="font-semibold">{upcomingLabel}</Text>
        {items.length ? (
          <List>
            {items.map((item, index) => (
              <Fragment key={isValidElement(item) ? item.key : index}>
                {index > 0 ? <ListSeparator /> : null}
                {item}
              </Fragment>
            ))}
          </List>
        ) : (
          <Text variant="muted">{emptyMessage}</Text>
        )}
        {actions}
      </View>
    </View>
  )
}

interface PlaybackQueueItemLabels {
  play: string
  playNext: string
  moveEarlier: string
  moveLater: string
  remove: string
}

export interface PlaybackQueueItemProps extends ViewProps {
  className?: string
  title: string
  detail?: string
  /** A localized duration, for example "3:42". */
  duration?: string
  artwork?: ReactNode
  onPlay?: () => void
  /** Place this item first in the upcoming queue. */
  onPlayNext?: () => void
  onMoveEarlier?: () => void
  onMoveLater?: () => void
  onRemove?: () => void
  disabled?: boolean
  /** Localized accessible name for the row's overflow menu. */
  actionsLabel?: string
  labels?: Partial<PlaybackQueueItemLabels>
}

export function PlaybackQueueItem({
  title,
  detail,
  duration,
  artwork,
  onPlay,
  onPlayNext,
  onMoveEarlier,
  onMoveLater,
  onRemove,
  disabled = false,
  actionsLabel,
  labels,
  accessibilityLabel,
  className,
  ...props
}: PlaybackQueueItemProps) {
  const hasOrderActions = onPlayNext || onMoveEarlier || onMoveLater

  return (
    <View {...props} className={cn('flex-row items-center gap-[4px] px-[4px] py-[4px]', className)}>
      <ListItem
        className="min-w-0 flex-1 rounded-md px-[8px] py-[8px]"
        disabled={disabled}
        onPress={
          onPlay
            ? () => {
                if (!disabled) onPlay()
              }
            : undefined
        }
        accessibilityLabel={
          onPlay ? (accessibilityLabel ?? [title, detail, duration].filter(Boolean).join(', ')) : accessibilityLabel
        }
        accessibilityHint={onPlay && !disabled ? (labels?.play ?? 'Play now') : undefined}
      >
        {artwork ? (
          <View accessibilityElementsHidden importantForAccessibility="no-hide-descendants" aria-hidden>
            {artwork}
          </View>
        ) : (
          <View className="size-[40px] items-center justify-center rounded-md bg-muted">
            <Icon icon={Play} size={17} className="text-muted-foreground" />
          </View>
        )}
        <ListItemContent>
          <ListItemTitle>{title}</ListItemTitle>
          {detail ? <ListItemDescription>{detail}</ListItemDescription> : null}
          {duration ? (
            <ListItemDescription style={{ fontVariant: ['tabular-nums'] }}>{duration}</ListItemDescription>
          ) : null}
        </ListItemContent>
      </ListItem>
      {!disabled && (hasOrderActions || onRemove) ? (
        <DropdownMenu className="self-center">
          <DropdownMenuTrigger
            className="border-transparent bg-transparent px-0 py-0"
            accessibilityLabel={actionsLabel ?? `Queue actions for ${title}`}
          >
            <Icon icon={Ellipsis} size={20} />
          </DropdownMenuTrigger>
          <DropdownMenuContent align="end">
            {onPlayNext ? (
              <DropdownMenuItem onPress={onPlayNext}>{labels?.playNext ?? 'Play next'}</DropdownMenuItem>
            ) : null}
            {onMoveEarlier ? (
              <DropdownMenuItem onPress={onMoveEarlier}>{labels?.moveEarlier ?? 'Move earlier'}</DropdownMenuItem>
            ) : null}
            {onMoveLater ? (
              <DropdownMenuItem onPress={onMoveLater}>{labels?.moveLater ?? 'Move later'}</DropdownMenuItem>
            ) : null}
            {hasOrderActions && onRemove ? <DropdownMenuSeparator /> : null}
            {onRemove ? (
              <DropdownMenuItem onPress={onRemove}>{labels?.remove ?? 'Remove from queue'}</DropdownMenuItem>
            ) : null}
          </DropdownMenuContent>
        </DropdownMenu>
      ) : null}
    </View>
  )
}
components/blocks/playback-queue/index.ts
export { PlaybackQueue, PlaybackQueueItem, type PlaybackQueueItemProps, type PlaybackQueueProps } from './PlaybackQueue'

Dependencies

Registry items

npm packages

  • lucide-react-native
Browse media and playback