Scroll and Lists
Use Scroll for one composed child and a list component for large collections.
Native lists recycle platform rows and keep scrolling away from the PHP render
path.
ScrollView
Section titled “ScrollView”use Pam\Native\ScrollKeyboardDismissMode;use Pam\Native\UI\Column;use Pam\Native\UI\Scroll;
$content = Scroll::make( Column::make(...$sections),) ->showsIndicator(false) ->fillViewport() ->nestedScrollEnabled() ->keyboardDismissMode(ScrollKeyboardDismissMode::OnDrag) ->onScroll(fn ($event) => $this->rememberOffset($event));ScrollView::make($content) is the compatibility alias. Horizontal paging can
combine horizontal(), pagingEnabled(), snapToInterval() and a bounded
deceleration rate.
In a .pam.php template, declarative ScrollView accepts one or many direct
children. PAM Native 0.5.46 inserts a native Row for horizontal content and a
native Column for vertical content:
<ScrollView horizontal="true" showsHorizontalScrollIndicator="false"> <Pressable p-for="$story in $stories" :key="$story->id" width="66" > <Image :source="$story->avatar" width="66" height="66" /> <Text>{{ $story->name }}</Text> </Pressable></ScrollView>This keeps compact items at their authored width even when only one branch is
currently visible, while loops and conditions can safely produce multiple
items. The imperative Scroll::make($content) API remains explicit and still
accepts exactly one content element.
Imperative jumps and restoration
Section titled “Imperative jumps and restoration”PAM Native 0.5.29 adds tokenized scroll requests. A changed request number
executes exactly once on the native UI thread. PAM Native 0.5.60 also accepts
a persisted logical offset on that request. A testId has first priority, a
non-negative offset is second, and omitting both targets jumps to the content
end.
<ScrollView anchorToEnd="true" maintainVisibleContentPosition="true" :scrollTargetTestId="$scrollTarget" :scrollTargetOffset="$scrollTargetOffset" :scrollRequest="$scrollRequest"> <Column> <Row testId="first-unread"> <Text>Unread messages</Text> </Row> </Column></ScrollView>public string $scrollTarget = '';public float $scrollTargetOffset = -1.0;public int $scrollRequest = 0;
public function jumpToUnread(): void{ $this->scrollTarget = 'first-unread'; $this->scrollTargetOffset = -1.0; $this->scrollRequest++;}
public function restoreReadingPosition(float $offset): void{ $this->scrollTarget = ''; $this->scrollTargetOffset = max(0.0, $offset); $this->scrollRequest++;}
public function jumpToLatest(): void{ $this->scrollTarget = ''; $this->scrollTargetOffset = -1.0; $this->scrollRequest++;}The fluent PHP equivalent is
$scroll->scrollRequest($request, $targetTestId, $targetOffset). Keep the
request value in component state. The offset is expressed in logical points,
not physical pixels. Because it is part of a one-shot request, it restores
state without making the scroll continuously controlled or bouncing against
the user’s gesture.
anchorToEnd() controls initial placement and following new content while the
viewport is already near the end. maintainVisibleContentPosition() preserves
the visible region when older content is prepended. Scroll requests are
explicit user or application commands and take precedence when dispatched.
FlatList
Section titled “FlatList”FlatList is optimized for native text rows:
use Pam\Native\UI\FlatList;
$list = FlatList::make(array_map( fn ($contact) => $contact->displayName, $contacts,)) ->rowHeight(56) ->prefetch(8) ->initialScrollIndex($restoredIndex) ->removeClippedSubviews() ->onEndReached(fn () => $this->loadNextPage(), threshold: 0.35);NativeList preserves the original, narrower string-row API for existing
applications:
use Pam\Native\UI\NativeList;
return NativeList::make($recentSearches) ->rowHeight(48) ->prefetch(12) ->onEndReached(fn () => $this->loadMore(), threshold: 0.6);Every item must be a string. Row height and prefetch are clamped to at least
one, and the threshold to 0.0–1.0. Prefer FlatList for new string-row
screens because it additionally supports horizontal layout, columns, inversion,
initial index, clipping, indicators, scroll events, and bounded prefetch up to
32 rows. Use VirtualizedList for custom or heterogeneous cells.
VirtualizedList and SectionList
Section titled “VirtualizedList and SectionList”use Pam\Native\UI\SectionList;use Pam\Native\UI\Text;use Pam\Native\UI\VirtualizedList;
$cards = VirtualizedList::make( ...array_map( fn ($item) => ContactCard::make($item)->key("contact:{$item->id}"), $contacts, ),) ->estimatedRowHeight(72) ->prefetch(10) ->onEndReached(fn () => $this->loadMore());
$sections = SectionList::make([ ['title' => 'Favorites', 'items' => ['Ada', 'Linus']], ['title' => 'Recent', 'items' => ['Margaret', 'James']],])->rowHeight(52);Use stable keys for composed rows. VirtualGrid applies the same recycled
list contract to multi-column responsive cells.
For rich cells, estimatedRowHeight is a prefetch estimate and the fallback
when a cell has no authored main-axis size. Explicit cell heights remain
authoritative:
<VirtualizedList estimatedRowHeight="604" prefetch="4"> <Column p-for="$post in $posts" :key="$post['id']" :height="$post['rowHeight']" > <Image :source="$post['image']" widthPercent="100" :height="$post['mediaHeight']" /> </Column></VirtualizedList>PAM computes these extents in Rust and gives each recycled Android holder its
exact native size. Scrolling does not synchronously measure PHP components on
the UI thread. Horizontal rich lists use an explicit cell width the same
way, while rowHeight remains a compatibility alias.
The list viewport and each recycled holder are hard native paint boundaries.
Media cannot draw over headers, neighboring rows, or tab bars while scrolling.
Inside the cell, component-level overflow still controls descendant clipping.
Data-driven lists
Section titled “Data-driven lists”For anything that can grow (a feed, a chat, search results), build rows from
data with VirtualizedList::of(). The row closure runs only for rows that are
on screen (plus a margin around them), never for the whole collection up front,
like React Native’s FlatList data + renderItem + keyExtractor:
<?php
declare(strict_types=1);
namespace App\Screens;
use App\Components\OrderRow;use Pam\Native\Component;use Pam\Native\Element;use Pam\Native\Style;use Pam\Native\UI\Screen;use Pam\Native\UI\VirtualizedList;
final class OrdersScreen extends Component{ /** @var list<array{id: int, title: string, total: string}> */ public array $orders = [];
public function render(): Element { return Screen::make( VirtualizedList::of( $this->orders, fn (array $order) => new OrderRow($order['title'], $order['total']), fn (array $order) => "order:{$order['id']}", ) ->estimatedRowHeight(72) ->prefetch(6) ->contentContainerStyle(new Style(paddingVertical: 12)) ->onEndReached(fn () => $this->loadNextPage(), threshold: 0.4) ->style(new Style(flexGrow: 1)), )->style(new Style(flexGrow: 1)); }
public function loadNextPage(): void { // Append the next page to $this->orders. }}Keys default to the item’s key or id (array key or public property), then
to the index. Pass a key closure whenever items can be inserted, removed or
reordered so row state and recycled views follow the right item.
In Language 2 templates, every loop inside VirtualizedList or VirtualGrid
must declare p-key; a missing, duplicate or non-scalar key is a compile error
(PAM2201):
<VirtualizedList estimatedRowHeight="72"> <OrderRow p-for="$order in $orders" p-key="$order->id" :order="$order" /></VirtualizedList>List window
Section titled “List window”windowSize($n) (template windowSize="5") keeps only the rows within
(n - 1) / 2 screens above and below the visible ones built and mounted. The
others become placeholders with their last measured (or estimated) height, so
the scroll position never jumps. Rows that leave the window unmount their
components and lose local state, as in React Native. 5 suits tall media
rows. Without windowSize, vertical lists of more than 96 rows are windowed
automatically.
VirtualizedList::of($posts, fn (array $post) => new PostCard($post)) ->estimatedRowHeight(600) ->windowSize(5);Lean list rules
Section titled “Lean list rules”- Never render a growing collection as a
Columninside aScroll: every row stays mounted, measured and in memory. Use a recycled list. - Give rows an authored height, or a good
estimatedRowHeight, so scrolling never waits for measurement. - Keep
prefetchsmall (it is capped at 32 rows); prefetching many rows of media wastes memory and network. - Size every image in a row to its box (Images and cache).
- Pause row video and animations that scroll out of view; autoplay only what is visible.
- Load pages on
onEndReachedinstead of fetching everything at once. - Put the list’s top and bottom spacing in
contentContainerStyle(). It uses native scroll insets (no extra wrapper or rows), and the last row still ends above the navigation bar or home indicator; see Safe Areas.
Pull to refresh
Section titled “Pull to refresh”use Pam\Native\RefreshIndicatorSize;use Pam\Native\UI\RefreshControl;
$feed = RefreshControl::make($cards, $this->state->refreshing) ->colors(0xFF2563EB, 0xFF7C3AED) ->progressBackgroundColor(0xFFFFFFFF) ->size(RefreshIndicatorSize::Default) ->onRefresh(fn () => $this->refresh());Avoid rendering an unbounded collection into a Column inside Scroll.
Choose a recycled list whenever item count can grow with remote or user data.
Android has the mature recycled-list path; confirm the current iOS parity
record before relying on identical large-list behavior.