Skip to main content

Scroll Area

Scroll Area is a container that lets people scroll through overflowing content, such as an activity log or a row of photos.

Import

import { ScrollArea } from '@vortexlabs/vortex-native';
import type { ScrollAreaProps } from '@vortexlabs/vortex-native';

Other links

import { ScrollArea, Stack, Text } from "@vortexlabs/vortex-native";

<ScrollArea
  width={240}
  height={96}
  scrollbar="hover"
>
  <Stack gap={3} padding={2}>
  <Text>Order received</Text>
  <Text>Payment confirmed</Text>
  <Text>Order packed</Text>
  <Text>Parcel shipped</Text>
  <Text>Out for delivery</Text>
  <Text>Delivered</Text>
</Stack>
</ScrollArea>

Features

  • Scrolls horizontally or vertically.
  • Supports responsive bounds and system scroll indicators.
  • Reports progress on each axis from 0 to 1 and forwards a ref to the scroll view.
  • Keeps focused fields visible in vertical scroll areas.

Viewport Size

Set height to reserve a fixed viewport or maxHeight to let a short list use less space. Both accept breakpoint values. Use width or maxWidth to bound a horizontal list.

<ScrollArea maxHeight={{ xs: 160, md: 280 }}>
  <Stack gap={2}>
    {events.map((event) => <Text key={event.id}>{event.title}</Text>)}
  </Stack>
</ScrollArea>

Horizontal Scrolling

Use a bounded width for a horizontal strip. Set the inner layout direction to place items side by side.

<ScrollArea direction="horizontal" width={200}>
  <Stack direction="row" gap={4}>
    <Text>Overview</Text>
    <Text>Activity</Text>
    <Text>Collaborators</Text>
    <Text>Settings</Text>
  </Stack>
</ScrollArea>

Scroll Indicators

The default scrollbar="hover" shows the system indicator during a scroll. visible also flashes it once when the content first lays out. hidden removes the indicator while keeping scrolling available. On Android, edgeFade fades an edge when more content lies beyond it.

<ScrollArea height={160} scrollbar="visible" edgeFade>
  <ActivityEntries />
</ScrollArea>

Scroll Progress and Ref

onScroll reports progress from 0 to 1 on each axis. Keep the latest value in a ref to save a reading position on demand. Call scrollTo on the native scroll view ref to return to the top. For offsets in points, read the React Native event through attributes.onScroll.

import { Button, ScrollArea, Stack, Text } from "@vortexlabs/vortex-native";
import { useRef, useState } from "react";
import type { ScrollViewInstance } from "react-native";

export const ActivityLog = () => {
  const ref = useRef<ScrollViewInstance>(null);
  const progressRef = useRef(0);
  const [savedPercent, setSavedPercent] = useState<number | null>(null);

  return (
    <Stack gap={2} width={240}>
      <Text>{savedPercent === null ? "No reading position saved" : `Saved at ${savedPercent}%`}</Text>
      <ScrollArea
        ref={ref}
        height={96}
        onScroll={({ y }) => {
          progressRef.current = y;
        }}
      >
        <Stack gap={3} padding={2}>
          {["Order received", "Payment confirmed", "Order packed", "Parcel shipped", "Out for delivery", "Delivered"].map((entry) => (
            <Text key={entry}>{entry}</Text>
          ))}
        </Stack>
      </ScrollArea>
      <Button onPress={() => setSavedPercent(Math.round(progressRef.current * 100))}>
        Save reading position
      </Button>
      <Button onPress={() => ref.current?.scrollTo({ y: 0, animated: true })}>
        Back to top
      </Button>
    </Stack>
  );
};

Keyboard Avoidance

Vertical scroll areas keep the focused field above the on-screen keyboard on iOS and Android. VortexProvider supplies the keyboard context. Taps on controls inside the form reach their handlers while the keyboard is open.

import { ScrollArea, Stack, TextField } from "@vortexlabs/vortex-native";

<ScrollArea height={240}>
  <Stack gap={4} padding={3}>
    {["Street", "City", "State", "Postcode"].map((label) => (
      <TextField.Root key={label}>
        <TextField.Label>{label}</TextField.Label>
        <TextField.Input name={label} />
      </TextField.Root>
    ))}
  </Stack>
</ScrollArea>

Accessibility

Description
Keep inputs labeled and in reading order as the form scrolls.