For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/elements/built-in/scroll-view.md.
Lynx
  • English
  • <scroll-view>

    Basic scrolling component supporting both horizontal and vertical scrolling. When its content area is larger than its visible area, it allows users to scroll to reveal more content.

    Usage

    Horizontal and Vertical Scrolling

    <scroll-view> supports one scrolling axis at a time, configured by scroll-orientation (vertical by default). Give the view a bounded size along that axis so its content can exceed the visible area.

    <scroll-view> uses linear layout for its direct children, with the direction determined by scroll-orientation. To use Flexbox or another layout inside the scrolling content, place the content in a child <view>.

    Scroll Events

    Use event callbacks such as bindscroll, bindscrolltoupper, and bindscrolltolower to monitor changes in scroll progress.

    Sticky Capability

    Set the sticky attribute on a direct child of <scroll-view> to keep it at the configured edge offset as the content scrolls past it. For vertical scrolling, for example, use sticky with top: 0.

    Tip

    sticky can only be set for direct child nodes of <scroll-view>. On

    Android, you need to add the flatten={false} attribute to sticky nodes.

    The scroll container lays out its direct children linearly; this does not restrict the layout inside each child. A wrapper for more complex content can look like this:

    <scroll-view scroll-orientation="vertical" style={{ height: '300px' }}>
      <view style={{ display: 'flex', flexDirection: 'row' }}>
        <text>First item</text>
        <text>Second item</text>
      </view>
    </scroll-view>

    Attributes

    Support varies by platform and SDK version. See the compatibility table for version information. Numeric distances below use Lynx logical pixels (px), not physical device pixels.

    bounces

    iOS Desktop Harmony 1.4
    bounces?: boolean;

    Enables the bounce effect at the edges of the scrollable content. The default is true on iOS and on Clay for iOS/macOS, and false on HarmonyOS and on Clay for Windows. This attribute is not supported on Android, including Clay for Android.

    enable-scroll

    Android iOS Desktop Harmony 1.4
    // Default: true
    'enable-scroll'?: boolean;

    Controls whether users can scroll by dragging. Setting it to false does not disable explicit positioning through scrollTo or scrollBy. On Clay, starting autoScroll also requires scrolling to be enabled.

    initial-scroll-offset

    Android iOS Desktop Harmony 2.17
    // Default: 0
    'initial-scroll-offset'?: number;

    Sets the initial absolute scroll offset along the scrolling axis, in px. It is an initialization setting, not a controlled scroll position: use scrollTo for subsequent updates.

    Set either initial-scroll-offset or initial-scroll-to-index, rather than relying on a cross-platform precedence rule when both are supplied.

    initial-scroll-to-index

    Android iOS Desktop Harmony 2.17
    'initial-scroll-to-index'?: number;

    Initially positions the content at the specified direct child. The index is zero-based. Omitting this attribute does not select a child. Like initial-scroll-offset, it is intended for initialization; use scrollTo to change the position afterward.

    On Android, set flatten={false} on the direct children so their native node indices match the intended child indices. The index must refer to an existing child. Clay supports this attribute on Android, iOS, Windows, and macOS starting in version 4.5.

    lower-threshold

    Android iOS Desktop Harmony 1.4
    // Default: 0
    'lower-threshold'?: number;

    Sets the distance from the ending edge, in px, at which bindscrolltolower is triggered. In a vertical view this is the bottom edge; in a left-to-right horizontal view it is the right edge.

    scroll-bar-enable

    Android iOS Desktop Harmony 1.4
    // Default: false
    'scroll-bar-enable'?: boolean;

    Controls whether a scroll indicator is shown. Android's built-in scroll-view applies this attribute to the vertical indicator only. iOS, HarmonyOS, and Clay support indicators for both scrolling orientations.

    scroll-orientation

    Android iOS Desktop Harmony 3.0
    // Default: 'vertical'
    'scroll-orientation'?: 'vertical' | 'horizontal';

    Sets both the scrolling axis and the linear layout direction of the direct children. Prefer this attribute to the legacy scroll-x and scroll-y attributes.

    upper-threshold

    Android iOS Desktop Harmony 1.4
    // Default: 0
    'upper-threshold'?: number;

    Sets the distance from the starting edge, in px, at which bindscrolltoupper is triggered. In a vertical view this is the top edge; in a left-to-right horizontal view it is the left edge.

    Events

    Bind event handlers on <scroll-view> and read the payload from event.detail. The event name is available as event.type, not event.detail.type.

    bindcontentsizechanged

    Android iOS Desktop Harmony 1.6

    Fires when the content size changes, not after every layout or child update.

    interface ContentSizeChangedDetail {
      scrollWidth: number;
      scrollHeight: number;
    }

    Both dimensions describe the content, in px. This event can be used to reposition the view after its content size changes, but an update that leaves the content size unchanged does not guarantee this event.

    bindscroll

    Android iOS Desktop Harmony 1.4

    Fires as the scroll position changes. Its detail includes:

    interface ScrollDetail {
      scrollLeft: number;
      scrollTop: number;
      scrollWidth: number;
      scrollHeight: number;
      deltaX: number;
      deltaY: number;
    }

    scrollLeft and scrollTop are the content offsets; scrollWidth and scrollHeight are the content dimensions. deltaX and deltaY are the change in offset reported for the event. All values use px.

    bindscrollend

    Android iOS Desktop Harmony 1.6

    Fires when scrolling ends. Its detail contains the scroll offsets and content dimensions described under bindscroll. Use the offsets to read the final position, rather than treating deltaX or deltaY as the total distance of the scroll.

    bindscrolltolower

    Android iOS Desktop Harmony 1.4

    Fires when scrolling enters the ending-edge region defined by lower-threshold: the bottom edge for vertical scrolling, or the right edge for left-to-right horizontal scrolling.

    Its detail contains the same fields as bindscroll. Do not assume that deltaX and deltaY are always zero in threshold events; this differs between implementations.

    bindscrolltoupper

    Android iOS Desktop Harmony 1.4

    Fires when scrolling enters the starting-edge region defined by upper-threshold: the top edge for vertical scrolling, or the left edge for left-to-right horizontal scrolling. Its detail contains the same fields as bindscroll.

    For horizontal RTL content, Android, iOS, and Clay reverse the starting and ending edges. Do not rely on identical RTL threshold behavior on HarmonyOS.

    Methods

    Invoke methods through SelectorQuery. The examples below assume a <scroll-view id="scroll-view"> exists and has completed layout.

    autoScroll

    Android iOS Desktop Harmony

    Starts or stops continuous scrolling along the configured axis.

    lynx
      .createSelectorQuery()
      .select('#scroll-view')
      .invoke({
        method: 'autoScroll',
        params: {
          rate: 120,
          start: true,
        },
      })
      .exec();
    • rate: numeric speed in px per second. Android, iOS, and HarmonyOS support positive and negative values. Clay starts automatic scrolling only for a positive rate.
    • start: true starts scrolling; false stops it. To stop, invoke the method again with { rate: 0, start: false }.

    Use a numeric rate for portability; unit-bearing strings such as "120rpx" are not supported consistently. With the default behavior, automatic scrolling stops at the content boundary and does not restart simply because the user drags away from that boundary.

    getScrollInfo

    Android iOS Desktop Harmony

    Reads the current scroll position.

    interface GetScrollInfoResult {
      scrollX: number;
      scrollY: number;
      scrollRange: number;
      maxScrollOffset?: number;
    }
    
    lynx
      .createSelectorQuery()
      .select('#scroll-view')
      .invoke({
        method: 'getScrollInfo',
        success: (res: GetScrollInfoResult) => {
          console.log(res.scrollX, res.scrollY);
        },
      })
      .exec();

    scrollX and scrollY are the content offsets in px.

    The meaning of scrollRange differs by platform: Android, HarmonyOS, and Clay return the content length minus the viewport length along the scrolling axis; iOS preserves the legacy meaning of the full content length. Current iOS implementations additionally return maxScrollOffset for the maximum offset. Do not use scrollRange as a portable maximum scroll offset.

    scrollBy

    Android iOS Harmony

    Moves relative to the current position along the scrolling axis. Clay does not expose this UI method.

    lynx
      .createSelectorQuery()
      .select('#scroll-view')
      .invoke({
        method: 'scrollBy',
        params: { offset: 100 },
        success: (res) => {
          console.log(res.consumedX, res.consumedY);
        },
      })
      .exec();

    Supply a numeric offset in px. Positive and negative values scroll in opposite directions. Unlike scrollTo, the offset is relative to the current position.

    The result contains consumedX, consumedY, unconsumedX, and unconsumedY, in px. Read the pair corresponding to the scrolling axis to determine how much of the requested movement was consumed.

    scrollTo

    Android iOS Desktop Harmony

    Positions the content at an absolute offset or relative to a direct child.

    interface ScrollToParams {
      index?: number;
      offset?: number;
      smooth?: boolean;
    }
    
    const params: ScrollToParams = { offset: 100, smooth: true };
    
    lynx
      .createSelectorQuery()
      .select('#scroll-view')
      .invoke({
        method: 'scrollTo',
        params,
        fail: (error) => {
          console.error(error);
        },
      })
      .exec();
    • Without index, offset is the absolute content offset in px, not a distance from the current position.
    • With index, the zero-based index selects a direct child and offset is added to that child's position. For example, { index: 1, offset: 0 } aligns the second child. On Android, use flatten={false} on the direct children when positioning by index.
    • offset defaults to 0; smooth defaults to false. Omitting index is not equivalent to index: 0, for example when the first child is inset by padding or margin.

    Use an existing child index and a target within the scrollable range. Out-of-range handling and callback timing differ across platforms; do not use the success callback as a cross-platform animation-completion signal. For horizontal RTL positioning by index, Android, iOS, and Clay align to the child's right edge and subtract the offset; HarmonyOS uses the child's left position plus the offset.

    scrollIntoView

    Android iOS Desktop Harmony

    Invoke this method on the target descendant, not on the scroll container, to bring the target into its ancestor scroll view. On Android, the target must have a native view; set flatten={false} when necessary.

    lynx
      .createSelectorQuery()
      .select('#scroll-target')
      .invoke({
        method: 'scrollIntoView',
        params: {
          scrollIntoViewOptions: {
            behavior: 'smooth',
            block: 'center',
            inline: 'start',
          },
        },
      })
      .exec();

    scrollIntoViewOptions is required. Use behavior: 'smooth' for animated scrolling or 'auto' for immediate positioning. Use block for vertical alignment and inline for horizontal alignment; explicitly choose 'start', 'center', or 'end' for consistent alignment rather than relying on platform-specific defaults.

    Performance Optimization Suggestions

    <scroll-view> creates all supplied child nodes and does not virtualize or recycle them. Large amounts of content can increase initial rendering time and memory usage.

    For long or growing collections, prefer <list>. Exposure events can help defer expensive work, but do not turn <scroll-view> into a virtualized list or automatically remove off-screen nodes.

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.