Scroll View
Overview
ScrollView is a headless @vyui/core scroll container. By default it is a thin wrapper that forwards native scrolling and edge-threshold events; opt into enableBounces for a custom main-thread bounce/overscroll system with parity to lynx-ui.
@vyui/core primitive (adapted from lynx-ui, Apache 2.0). Behavior only, no styles.Usage
<script setup lang="ts">
import { ScrollView } from '@vyui/core'
function onLower() {
// load more
}
</script>
<template>
<ScrollView
scroll-orientation="vertical"
:lower-threshold="80"
@scroll-to-lower="onLower"
>
<view
v-for="n in 50"
:key="n"
class="p-4"
>
<text>Row {{ n }}</text>
</view>
</ScrollView>
</template>
Features and behavior
scrollOrientationchooses'vertical'(default) or'horizontal'.upperThreshold/lowerThresholdset the distance from each edge that firesscrollToUpper/scrollToLower— useful for infinite loading.bouncesforwards the native bounce (iOS / Harmony / PC);scrollBarEnableshows the native scroll bar.enableBouncesturns on the custom main-thread bounce. ThenstartBounceTriggerDistance/endBounceTriggerDistance,alwaysBouncing, and the bounce edges control overscroll, emittingscrollToBounces.idis required by the bounce system to select the container on the main thread; it is auto-generated when omitted.
API
Props
| Prop | Default | Type |
|---|---|---|
alwaysBouncing | true | boolean | undefinedAllow bouncing even when the content is smaller than the viewport. |
bounces | true | boolean | undefinedEnable native bounce on iOS / Harmony / PC. Ignored when `enableBounces` turns on the custom main-thread bounce. |
debugLog | false | boolean | undefinedEmit verbose bounce diagnostics to the console. |
disabled | false | boolean | undefinedDisable scrolling. |
enableBounceEventInFling | true | boolean | undefinedFire `scrollToBounces` when the bounce is reached during a fling, not only during a finger-down drag. |
enableBounces | false | boolean | undefinedTurn on the custom main-thread bounce/overscroll system. When `false` (default) the component is a thin wrapper that only forwards the native `bounces` prop. |
enableRTL | false | boolean | undefinedMirror horizontal bounce direction for RTL layouts. |
endBounceTriggerDistance | 0 | number | undefinedOverscroll distance (px) past the lower edge required to fire `scrollToBounces` with `{ direction: 'lower' }`. |
estimatedHeight | — | number | undefinedSize hint (px) used by the bounce maths before the first layout pass. |
estimatedWidth | — | number | undefinedHorizontal size hint (px) used before first layout. |
id | — | string | undefinedStable id for the scroll container. Required by the bounce system to select the container / bounce wrappers on the main thread. Auto-generated when omitted. |
lowerThreshold | 0 | number | undefinedDistance (px) from the lower edge that fires `scrollToLower`. |
scrollBarEnable | true | boolean | undefinedShow the native scroll bar. |
scrollOrientation | "vertical" | "vertical" | "horizontal" | undefinedScroll direction. |
singleSidedBounce | "both" | SingleSidedBounce | undefinedWhich edge(s) may bounce. |
startBounceTriggerDistance | 0 | number | undefinedOverscroll distance (px) past the upper edge required to fire `scrollToBounces` with `{ direction: 'upper' }`. |
upperThreshold | 0 | number | undefinedDistance (px) from the upper edge that fires `scrollToUpper`. |
Emits
| Event | Payload |
|---|---|
scrollToLower | [event: unknown] |
scrollToUpper | [event: unknown] |
scroll | [event: unknown] |
scrollEnd | [event: unknown] |
scrollToBounces | [info: ScrollToBouncesInfo] |
Platform notes
- The custom bounce runs through main-thread (MTS) worklets; without
enableBouncesthe component is a thin pass-through to native scrolling.