Hooks

useDocyrusAdaptiveCardItemList

Generate an array of Adaptive Card JSON payloads from a Docyrus field list + many records, and render them as a responsive grid, a stacked list, a single Carousel card or a single Table card with the shared native AdaptiveCard renderer.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-adaptive-card-item-list
Required Packages(1 package)
pnpm add react

The signature is identical to web @docyrus/ui. Only the rendered view differs: it is built from React Native Views.

Overview

useDocyrusAdaptiveCardItemList is the list companion of useDocyrusAdaptiveCardItemDetail. You hand it a Docyrus field list + a list of records and it generates one Adaptive Card JSON payload per record (cards) — mapping Docyrus field types onto the Adaptive Cards element vocabulary — then renders them with the shared AdaptiveCard renderer.

Both hooks share the same backend-agnostic mapper, so a card looks identical whether it's shown alone (detail) or in a list. Four layouts are supported:

  • grid (default) — rows of equal-width cards. With columns: 'flex' the column count is derived from the window width (useWindowDimensions): floor((width + gap) / (minCardWidth + gap)), at least 1. A phone therefore gets one column and a tablet gets two or more. A fixed number pins the count.
  • list — a single stacked column of cards.
  • carousel — one combined Adaptive Card whose Carousel pages are the per-record bodies.
  • table — one combined Adaptive Card whose Table has a field-label header row and one row per record (scalar fields become columns; images / rich-text / code are excluded). The native Table element gives every column a fixed width (3 × 50 = 150 px) and scrolls horizontally inside a ScrollView when the columns are wider than the card.

When a DocyrusTenantProvider is mounted, dates / numbers / currency are formatted with the tenant's preferences.

See useDocyrusAdaptiveCardItemDetail for the full field-type → element mapping and slot-detection rules.

Usage

Render a responsive grid of cards

import { ScrollView } from 'react-native';

import { useDocyrusAdaptiveCardItemList } from '@/hooks/docyrus-native/use-docyrus-adaptive-card-item-list';

export function DealGallery({ fields, records }) {
  const { view } = useDocyrusAdaptiveCardItemList({
    fields,
    records,
    layout: 'grid',
    columns: 'flex',
    minCardWidth: 340
  });

  return <ScrollView contentContainerClassName="p-4">{view}</ScrollView>;
}

The view is a plain, non-virtualized View tree, so it can sit inside a ScrollView. For hundreds of records, render items yourself in a FlashList (numColumns) with one <AdaptiveCard payload={item.card} /> per cell.

Per-card actions + scoped click handler

onItemAction receives the originating record and index, so one handler routes every card (not applied in carousel or table layout).

const { view } = useDocyrusAdaptiveCardItemList({
  fields,
  records,
  getItemActions: (record) => [
    { type: 'Action.OpenUrl', title: 'Open', url: `myapp://deals/${record.id}` }
  ],
  onItemAction: (event, record) => {
    if (event.type === 'openUrl') router.push(event.url);
  }
});

Use the generated JSON array directly

const { cards, items } = useDocyrusAdaptiveCardItemList({ fields, records });

// `cards` is AdaptiveCardPayload[] — one per record
// `items` is [{ id, record, card }] if you need the record alongside its card
await syncToTeams(cards);
const { view, carouselCard } = useDocyrusAdaptiveCardItemList({
  fields,
  records,
  layout: 'carousel'
});

// `carouselCard` is the single combined AdaptiveCardPayload (a Carousel).
return view;

Table

const { view, tableCard } = useDocyrusAdaptiveCardItemList({
  fields,
  records,
  layout: 'table'
});

// `tableCard` is the single combined AdaptiveCardPayload (a Table:
// header row = field labels, one row per record). Scrolls horizontally
// when wider than its container.
return view;

API Reference

UseDocyrusAdaptiveCardItemListOptions

OptionTypeDefaultDescription
fieldsDocyrusAdaptiveCardField[]—Field metadata (accepts IField / DataSourceField / DocyrusFieldLike).
recordsRecord<string, unknown>[] | null—Records to render as cards.
enumOptionsRecord<string, EnumOption[]>—Per-field-slug enum options. Falls back to each field's inline enums.
slotsDocyrusAdaptiveCardSlotOverrides—Slot bindings shared by every card.
includeFieldsstring[]—Explicit, ordered body field list.
excludeFieldsstring[]—Field slugs to drop from every card body.
hideEmptybooleantrueDrop empty fields instead of rendering an em-dash.
factLayout'facts' | 'stacked''facts'Scalar layout — a FactSet or stacked label/value blocks.
versionstring'1.5'Adaptive Card schema version.
getRecordId(record, index) => stringrecord.id → indexStable key per record.
getItemTitle(record, index) => string | undefined—Per-card title override.
getItemActions(record, index) => AdaptiveCardAction[] | undefined—Per-card actions.
onItemAction(event: AdaptiveCardActionEvent, record, index) => void | Promise<void>—Action handler scoped to the record. Not applied in carousel / table.
layout'grid' | 'list' | 'carousel' | 'table''grid'Rendered layout. carousel / table produce one combined card.
columnsnumber | 'flex''flex'Grid columns. 'flex' derives the count from the window width and minCardWidth.
minCardWidthnumber320Minimum card width (px) for the 'flex' grid.
gapnumber16Gap (px) between cards.
classNamestring—className for the list container View (or the combined carousel / table card).
cardClassNamestring—className for each card (grid / list).
emptyContentReactNodebuilt-inShown when there are no records. The built-in state reads ui.adaptiveCard.noRecords (fallback "No records to display.") through useUiTranslation.
formatDate(value: unknown) => stringtenant contextOverride the date formatter.
formatDateTime(value: unknown) => stringtenant contextOverride the datetime formatter.
formatNumberDocyrusAdaptiveCardFormatters['formatNumber']tenant contextOverride the number / currency / percent formatter.
hostConfigAdaptiveCardHostConfigOverride—Forwarded to every rendered card.
customElementsRecord<string, ElementRenderer>—Forwarded to every rendered card.

UseDocyrusAdaptiveCardItemListReturn

FieldTypeDescription
cardsAdaptiveCardPayload[]The generated Adaptive Card JSON payloads — the primary output.
itemsDocyrusAdaptiveCardListItem[]{ id, record, card } per record.
slotsDocyrusAdaptiveCardSlotsSlot bindings shared by every card.
carouselCardAdaptiveCardPayload | nullCombined Carousel card in carousel layout, else null.
tableCardAdaptiveCardPayload | nullCombined Table card in table layout (header row = field labels, one row per record), else null.
viewReactNodeReady-to-render list element.

Type Exports

TypeDescription
UseDocyrusAdaptiveCardItemListOptionsHook options.
UseDocyrusAdaptiveCardItemListReturnHook return.
DocyrusAdaptiveCardListItem{ id, record, card }.
DocyrusAdaptiveCardListLayout'grid' | 'list' | 'carousel' | 'table'.
DocyrusAdaptiveCardFieldMinimal field shape.
DocyrusAdaptiveCardSlots / DocyrusAdaptiveCardSlotOverridesSlot bindings / overrides.
DocyrusAdaptiveCardFactLayout'facts' | 'stacked'.

See also

On this page