Scrollable Component Common APIs

The common attributes and events for scrollable components currently only support the List, Grid, Scroll, and WaterFlow components.

NOTE

The initial APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.

Attributes

scrollBar11+

scrollBar(barState: BarState): T

Sets the scrollbar state.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
barState BarState Yes Scrollbar state.
Default value: BarState.Auto for the List, Grid, and Scroll components and BarState.Off for the WaterFlow component

Return value

Type Description
T Current scrollable component.

scrollBarColor11+

scrollBarColor(color: Color | number | string): T

Sets the scrollbar color.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
color Color | number | string Yes Scrollbar color.
Default value: '#182431' (40% opacity)
A number value indicates a HEX color in RGB or ARGB format, for example, 0xffffff. A string value indicates a color in RGB or ARGB format, for example, '#ffffff'.

Return value

Type Description
T Current scrollable component.

scrollBarColor22+

scrollBarColor(color: Color | number | string | Resource): T

Sets the scrollbar color. Compared with scrollBarColor11+, this API supports the Resource type for the color parameter.

Atomic service API: This API can be used in atomic services since API version 22.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
color Color | number | string | Resource Yes Scrollbar color.
Default value: '#182431' (40% opacity)
A number value indicates a HEX color in RGB or ARGB format, for example, 0xffffff. A string value indicates a color in RGB or ARGB format, for example, '#ffffff'.

Return value

Type Description
T Current scrollable component.

scrollBarWidth11+

scrollBarWidth(value: number | string): T

Sets the scrollbar width. This attribute cannot be set in percentage. After the width is set, the scrollbar is displayed with the set width in normal state and pressed state. If the set width exceeds the height of the scrollable component on the main axis, the scrollbar reverts to the default width.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value number | string Yes Scrollbar width.
Default value: 4
Unit: vp
If this parameter is set to a value less than or equal to 0, the default value is used. The value 0 means not to show the scrollbar.

Return value

Type Description
T Current scrollable component.

scrollBarWidth

scrollBarWidth(value: number | string | Resource): T

Sets the scrollbar width. This attribute cannot be set in percentage. After the width is set, the scrollbar is displayed with the set width in normal state and pressed state. If the set width exceeds the height of the scrollable component on the main axis, the scrollbar width changes to 4 vp. The Resource type is supported.

If this attribute is not set, the scrollbar width is 4 vp.

Since: 26.0.0

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value number | string | Resource Yes Scrollbar width.
Unit: vp
Value range: [0, +∞). If this parameter is set to a value less than 0, 4vp is used. The value 0 means not to show the scrollbar.

Return value

Type Description
T Current scrollable component.

edgeEffect11+

edgeEffect(edgeEffect: EdgeEffect, options?: EdgeEffectOptions): T

Sets the effect used when the scroll boundary is reached.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
edgeEffect EdgeEffect Yes Effect used when the scroll boundary is reached. The spring and shadow effects are supported.
Default value: EdgeEffect.None for the Grid, Scroll, and WaterFlow components and EdgeEffect.Spring for the List component
options EdgeEffectOptions No Whether edge effects are enabled when content is smaller than component size, and effective edges. The value { alwaysEnabled: true } means to enable the scroll effect, and { alwaysEnabled: false } means the opposite.
Default value:
For the List, Grid, and WaterFlow components, the default value is { alwaysEnabled: false, EffectEdge: EffectEdge.START | EffectEdge.END}. For the Scroll component, the default value is { alwaysEnabled: true, EffectEdge: EffectEdge.START | EffectEdge.END}.

Return value

Type Description
T Current scrollable component.

nestedScroll11+

nestedScroll(value: NestedScrollOptions): T

Sets the nested scrolling mode in the forward and backward directions to implement scrolling linkage with the parent component.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value NestedScrollOptions Yes Nested scrolling options.
Default value: { scrollForward: NestedScrollMode.SELF_ONLY, scrollBackward: NestedScrollMode.SELF_ONLY }

Return value

Type Description
T Current scrollable component.

enableScrollInteraction11+

enableScrollInteraction(value: boolean): T

Sets whether to support scroll gestures.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value boolean Yes Whether to support scroll gestures. With the value true, scrolling via finger or mouse is enabled. With the value false, scrolling via finger or mouse is disabled, but this does not affect the scrolling APIs of the Scroller.
Default value: true

Return value

Type Description
T Current scrollable component.

friction11+

friction(value: number | Resource): T

Sets the friction coefficient. It applies only to gestures in the scrolling area, and it affects only indirectly the scroll chaining during the inertial scrolling process. If this attribute is set to a value less than or equal to 0, the default value is used.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value number | Resource Yes Friction coefficient.
Default value: 0.6 for non-wearable devices and 0.9 for wearable devices.
Since API version 11, the default value for non-wearable devices is 0.7.
Since API version 12, the default value for non-wearable devices is 0.75.
Value range: (0, +∞). If this parameter is set to a value less than or equal to 0, the default value is used.

Return value

Type Description
T Current scrollable component.

flingSpeedLimit11+

flingSpeedLimit(speedLimit: number): T

Sets the maximum initial speed for inertial animation after a fling gesture.

NOTE

  • Inertial animation is the effect that the scrolling content continues to scroll and gradually decelerates and stops after the finger quickly flings and leaves the screen. It is also called inertial scrolling.

  • Inertial animation is triggered when the finger quickly flings and leaves the screen, or when the fling method is called.

  • Inertial animation is not generated when the mouse wheel or keyboard arrow keys are used to scroll, or when the scrollTo method is used to scroll to a specified position.

  • If the inertial animation is triggered by the fling method, the flingSpeedLimit setting does not take effect.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
speedLimit number Yes Maximum initial speed for inertial animation.
Default value: 9000
Unit: vp/s
Value range: (0, +∞). If this parameter is set to a value less than or equal to 0, the default value is used.

Return value

Type Description
T Current scrollable component.

fadingEdge14+

fadingEdge(enabled: Optional<boolean>, options?: FadingEdgeOptions): T

Sets whether to enable the edge fading effect and the length of the fading edge.

NOTE

The fadingEdge effect is implemented by configuring the overlay and blendMode attributes (parameter values: BlendMode.SRC_OVER and BlendApplyType.OFFSCREEN). When the fadingEdge effect takes effect, the .overlay() and .blendMode() attributes of the original component are overwritten. As a result, the screenshot APIs of the current component and its child components cannot capture the correct image. APIs that require screen capture: blur, linearGradientBlur, brightness, visualEffect, grayscale, saturate, contrast, invert, sepia, hueRotate, colorBlend, lightUpEffect, pixelStretchEffect, blendMode and backgroundBrightness.

When fadingEdge is enabled, avoid setting background-related attributes on the component with fadingEdge, as this may interfere with the fade effect.

With fadingEdge set to true, the component is clipped to the boundary, and setting the component's clip attribute to false will not take effect.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
enabled Optional<boolean> Yes Whether to enable the edge fading effect. true to enable, false otherwise.
Default value: false.
options FadingEdgeOptions No Object defining edge fading effect properties, such as the fading edge length.
If the value is less than 0, undefined, or not set, the default value is used. The default length is 32 vp.
If the value exceeds half the height of the container, it is adjusted to exactly half the height of the container.

Return value

Type Description
T Current scrollable component.

clipContent14+

clipContent(clip: ContentClipMode | RectShape): T

Sets the content clipping area for this scrollable component.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
clip ContentClipMode | RectShape Yes Clipping to apply, which is effective only for the content (that is, child components) of the scrollable component, not the background. When a custom rectangular area is passed through RectShape, only width, height, and offset relative to the component's upper left corner are supported, and rounded corners are not supported.
Default value: The default value for Grid and Scroll is ContentClipMode.BOUNDARY, and the default value for List and WaterFlow is ContentClipMode.CONTENT_ONLY.

Return value

Type Description
T Current scrollable component.

backToTop15+

backToTop(backToTop: boolean): T

Sets whether to enable the back-to-top feature for the scrollable component when the status bar is touched.

When a status bar touch event is received, the scrollable component on the current page can scroll to the top with an animation. This behavior does not affect scrollable components in background applications, which will not scroll to the top. This attribute is independent of the enableScrollInteraction setting.

Atomic service API: This API can be used in atomic services since API version 15.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
backToTop boolean Yes Whether to enable the back-to-top feature for the scrollable component when the status bar is touched. true to enable, false otherwise.
Default value:
Versions earlier than API version 18: false
API version 18 and later: false for horizontal scrolling and true for vertical scrolling

Return value

Type Description
T Current scrollable component.

scrollBarMargin20+

scrollBarMargin(margin: ScrollBarMargin): T

Sets the margin of the scrollbar. The margin is calculated from the offset distance where the scrollbar avoids corners. If the scrollbar area is smaller than the minimum scrollbar length, the scrollbar remains hidden.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
margin ScrollBarMargin Yes Start and end margins of the scrollbar.
Default value: {start: LengthMetrics.vp(0), end: LengthMetrics.vp(0)}

Return value

Type Description
T Current scrollable component.

autoAdjustScrollBarMargin

autoAdjustScrollBarMargin(enable: boolean | undefined): T

Sets whether to automatically adjust the margin of the scrollbar. By default, the margin is not automatically adjusted.

When the automatic margin adjustment feature is enabled, the scrolling direction of the scrollbar avoids the padding, safeAreaPadding and contentStartOffset/contentEndOffset areas of the component. If the scrollBarMargin attribute is set, this feature does not take effect. If the sum of the horizontal padding, safeAreaPadding, contentStartOffset and contentEndOffset values is greater than the width of the component, or the sum of the vertical values is greater than the height of the component, the scrollbar is not displayed.

Since: 26.0.0

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
enable boolean | undefined Yes Whether to automatically adjust the margin.
true: yes.
false: no.
undefined: no.

Return value

Type Description
T Current component.

digitalCrownSensitivity18+

digitalCrownSensitivity(sensitivity: Optional<CrownSensitivity>): T

Sets the sensitivity of the digital crown's response to events.

A component must have focus to receive crown events. Focus control can be managed using focusable, defaultFocus, and focusOnTouch.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
sensitivity Optional<CrownSensitivity> Yes Sensitivity to the digital crown rotation.
Default value: CrownSensitivity.MEDIUM

Return value

Type Description
T Current scrollable component.

contentStartOffset22+

contentStartOffset(offset: number | Resource): T

Sets the offset from the start of the content area. When the component scrolls to the start position, the content area maintains a specified distance from the component's display boundary.

If the combined value of contentStartOffset and contentEndOffset exceeds the scrollable content area length, both offsets are reset to 0.

Atomic service API: This API can be used in atomic services since API version 22.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
offset number | Resource Yes Offset from the start of the content to the boundary of the content area.
Default value: 0
Unit: vp
Invalid values (negative numbers or non-numeric Resource values) revert to the default value.

Return value

Type Description
T Current scrollable component.

contentEndOffset22+

contentEndOffset(offset: number | Resource): T

Sets the offset from the end of the content area. When the component scrolls to the end position, the content area maintains a specified distance from the component's display boundary.

If the combined value of contentStartOffset and contentEndOffset exceeds the scrollable content area length, both offsets are reset to 0.

Atomic service API: This API can be used in atomic services since API version 22.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
offset number | Resource Yes Offset from content end to component display boundary.
Default value: 0
Unit: vp
Invalid values (negative numbers or non-numeric Resource values) revert to the default value.

Return value

Type Description
T Current scrollable component.

enableScrollWithMouse

enableScrollWithMouse(enabled: boolean | undefined): T

Sets whether to support scrolling by dragging with the left mouse button pressed. If this API is not called, scrolling by dragging with the left mouse button pressed is not supported by default.

Since: 26.0.0

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
enabled boolean | undefined Yes Whether to support scrolling by dragging with the left mouse button pressed.
true: yes.
false: no.
undefined: no.

Return value

Type Description
T Current component.

Events

onReachStart11+

onReachStart(event: () => void): T

Triggered when the scrollable component reaches the start position.

This event is triggered once when the component is initialized and once when the component scrolls to the start position. If the edge effect is set to a spring effect, this event is triggered once when the swipe passes the start position, and triggered again when the swipe rebounds back to the start position.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event () => void Yes Callback invoked when the scrollable component reaches the start position.

Return value

Type Description
T Current scrollable component.

onReachEnd11+

onReachEnd(event: () => void): T

Triggered when the scrollable component reaches the end position.

If the edge effect is set to a spring effect, this event is triggered once when the swipe passes the end position, and triggered again when the swipe rebounds back to the end position.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event () => void Yes Callback invoked when the scrollable component reaches the end position.

Return value

Type Description
T Current scrollable component.

onScrollStart11+

onScrollStart(event: () => void): T

Triggered when the scrollable component starts scrolling initiated by the user's finger dragging the component or its scrollbar. For animated scrolling initiated via the Scroller controller, this event is triggered when the animation starts.

Trigger conditions:

  1. The scrollable component starts scrolling, supporting various input settings including keyboard and mouse operations.

  2. Scrolling is initiated through scroller controller API calls with transition animation effects.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event () => void Yes Callback invoked when scrolling starts.

Return value

Type Description
T Current scrollable component.

onScrollStop11+

onScrollStop(event: () => void): T

Triggered when scrolling stops. This event is triggered when scrolling initiated by dragging the scrollable component or its scrollbar stops after the finger leaves the screen. For animated scrolling initiated via the Scroller controller, this event is triggered when the animation stops.

Trigger conditions:

  1. The scrollable component stops scrolling, supporting various input settings including keyboard and mouse operations.

  2. The animation stops after scroller controller API calls with transition effects.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event () => void Yes Callback invoked when scrolling stops.

Return value

Type Description
T Current scrollable component.

onWillScroll12+

onWillScroll(handler: Optional<OnWillScrollCallback>): T

Triggered when the scrollable component is about to scroll.

The callback provides the amount of offset that is about to be scrolled in the current frame, along with the current scroll status and the source of the scrolling operation. The offset provided in the callback is the calculated intended scrolling offset, not the final actual scrolling offset. You can specify the intended scrolling offset for the scrollable component through the return value of this callback. The parameter type of the onWillScroll API of the Scroll component is ScrollOnWillScrollCallback.

NOTE

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler Optional<OnWillScrollCallback> Yes Callback triggered when the scrollable component is about to scroll.

Return value

Type Description
T Current scrollable component.

onDidScroll12+

onDidScroll(handler: OnScrollCallback): T

Triggered when the scrollable component scrolls. The return value is the offset amount by which the list has scrolled and the current scroll state.

NOTE

This API can be called within attributeModifier since API version 14.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler OnScrollCallback Yes Callback triggered when the scrollable component scrolls.

Return value

Type Description
T Current scrollable component.

onScroll(deprecated)

onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void): T

Triggered when the scrollable component scrolls.

NOTE

This API is supported since API version 11 and deprecated since API version 12. If the onScroll events of the List, Grid, and WaterFlow components are triggered after the layout, you are advised to use onDidScroll instead. If the onScroll event of the Scroll component is triggered before the layout, you are advised to use onWillScroll instead.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event (scrollOffset: number, scrollState: ScrollState) => void Yes Callback triggered when the scrollable component scrolls.
scrollOffset: offset relative to the previous frame. The offset is positive when the scrollable component is scrolled up and negative when it is scrolled down. Unit: vp
scrollState: current scroll state.

Return value

Type Description
T Current scrollable component.

onWillStartDragging21+

onWillStartDragging(handler: VoidCallback): T

Triggered when the scrollable component starts to be dragged.

Widget capability: This API can be used in ArkTS widgets since API version 21.

Atomic service API: This API can be used in atomic services since API version 21.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler VoidCallback Yes Callback invoked when the scrollable component starts to be dragged.

Return value

Type Description
T Current scrollable component.

onWillStopDragging20+

onWillStopDragging(handler: OnWillStopDraggingCallback): T

Triggered when the scrollable component is released. It is not triggered for scrolling via mouse wheel.

Widget capability: This API can be used in ArkTS widgets since API version 20.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler OnWillStopDraggingCallback Yes Callback invoked when the scrollable component is released.

Return value

Type Description
T Current scrollable component.

onDidStopDragging21+

onDidStopDragging(handler: OnDidStopDraggingCallback): T

Triggered when dragging of the scrollable component ends.

Widget capability: This API can be used in ArkTS widgets since API version 21.

Atomic service API: This API can be used in atomic services since API version 21.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler OnDidStopDraggingCallback Yes Callback invoked when the scrollable component stops being dragged.

Return value

Type Description
T Current scrollable component.

onWillStartFling21+

onWillStartFling(handler: VoidCallback): T

Triggered when the scrollable component is about to initiate an inertial animation.

NOTE

  • If the inertial animation is triggered by the fling method, onWillStartFling is not triggered.

  • For details about the triggering scenarios of the inertial animation, see the description of flingSpeedLimit.

Widget capability: This API can be used in ArkTS widgets since API version 21.

Atomic service API: This API can be used in atomic services since API version 21.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler VoidCallback Yes Callback invoked when the scrollable component is about to initiate an inertial animation.

Return value

Type Description
T Current scrollable component.

onDidStopFling21+

onDidStopFling(handler: VoidCallback): T

Triggered when the inertial animation of the scrollable component ends. It is not triggered if the animation is interrupted by a new swipe gesture.

Widget capability: This API can be used in ArkTS widgets since API version 21.

Atomic service API: This API can be used in atomic services since API version 21.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
handler VoidCallback Yes Callback invoked when the inertial animation of the scrollable component ends.

Return value

Type Description
T Current scrollable component.

ItemDragInfo

Provides information about the drag point.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
x number No No X-coordinate of the dragged item, in vp.
y number No No Y-coordinate of the dragged item, in vp.

NestedScrollOptions10+

Implements an object used to configure the nestedScroll attribute.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
scrollForward NestedScrollMode No No Nested scrolling options when the scrollable component scrolls forward.
scrollBackward NestedScrollMode No No Nested scrolling options when the scrollable component scrolls backward.

EdgeEffectOptions11+

Implements an object used to configure the edgeEffect attribute.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
alwaysEnabled boolean No No Whether to enable the scroll effect when the component content is smaller than the component itself. true to enable, false otherwise. The default value is false for the List, Grid, and WaterFlow components, and true for the Scroll component.
Atomic service API: This API can be used in atomic services since API version 12.
effectEdge18+ number No Yes Edge where the edge effect is applied.
With EffectEdge.START, the edge effect is applied to the start edge only. With EffectEdge.END, the edge effect is applied to the end edge only.
The default value is EffectEdge.START | EffectEdge.END, which means that the edge effect is applied to both the start and end edges. If an invalid value is set, the edge effect is applied to both the start and end edges.
To disable the effect on both edges, set edgeEffect to EdgeEffect.None.
Atomic service API: This API can be used in atomic services since API version 18.

FadingEdgeOptions14+

Implements an object used to configure the fadingEdge attribute.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
fadingEdgeLength LengthMetrics No Yes Length of the fading edge.

EditModeOptions23+

Sets attributes of the List or Grid component in edit mode.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
enableGatherSelectedItemsAnimation boolean No Yes Whether to enable the multi-selection gather animation. If this parameter is set to true, the gather animation is enabled. If this parameter is set to false, the gather animation is disabled.
The multi-selection gather animation is displayed only when bindContextMenu is set on GridItem or ListItem, responseType is set to ResponseType.LongPress, and preview is set to MenuPreviewMode.IMAGE or CustomBuilder.
If drag events are set on GridItem or ListItem, whether to enable the gather animation is subject to the dragPreviewOptions setting.
Default value: false.
Atomic service API: This API can be used in atomic services since API version 23.
onGetPreviewBadge OnGetPreviewBadgeCallback No Yes Callback triggered to obtain the number of selected items when the animation for gathering selected items upon long press is about to start.
If this parameter is omitted, the number of selected items within the display range of the Grid or List component is used as the badge for the menu preview image shown after the animation for gathering selected items upon long press.
Atomic service API: This API can be used in atomic services since API version 23.
useDefaultMultiSelectStyle boolean No Yes Whether to use the default multi-selection style.
The value true indicates that the check box is displayed after the GridItem or ListItem enters the multi-selection state. The value false indicates that no default style is available after the GridItem or ListItem enters the multi-selection state.
Default value: true
Since: 26.0.0
Atomic service API: This API can be used in atomic services since API version 26.0.0.

EffectEdge18+

Enumerates the edges where the edge effect is applied.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Value Description
START 1 Start edge.
END 2 End edge.

ContentClipMode14+

Enumerates the content clipping modes for the scrollable container.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

The figure below illustrates the clipping areas corresponding to each enumeration value after the component has been configured with margin and padding attributes.

ContentClipMode

Name Value Description
CONTENT_ONLY 0 Clip to the content area, corresponding to the green area in the figure.
BOUNDARY 1 Clip to the component area, corresponding to the entire blue area in the figure.
SAFE_AREA 2 Clip to the safe area configured for the component, corresponding to the entire yellow area in the figure.

OnWillScrollCallback12+

type OnWillScrollCallback = (scrollOffset: number, scrollState: ScrollState, scrollSource: ScrollSource) => void | ScrollResult

Triggered when the scrollable component is about to scroll.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
scrollOffset number Yes Offset relative to the previous frame. The offset is positive when the scrollable component is scrolled up and negative when it is scrolled down.
Unit: vp
scrollState ScrollState Yes Current scroll state.
scrollSource ScrollSource Yes Source of the current scrolling operation.

Return value

Type Description
void | ScrollResult Returns a ScrollResult object if the scrollable component scrolls by the developer-specified offset relative to the previous frame; returns no ScrollResult object if the component scrolls by the offset specified by scrollOffset in the callback.
Value range: (-∞, +∞)

OnScrollCallback12+

type OnScrollCallback = (scrollOffset: number, scrollState: ScrollState) => void

Triggered when the scrollable component scrolls.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
scrollOffset number Yes Offset relative to the previous frame. The offset is positive when the scrollable component is scrolled up and negative when it is scrolled down.
Unit: vp
scrollState ScrollState Yes Current scroll state.

OnItemDragStartCallback23+

type OnItemDragStartCallback = (event: ItemDragInfo, itemIndex: number) => CustomBuilder

Called when a list or grid element starts to be dragged.

Atomic service API: This API can be used in atomic services since API version 23.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
event ItemDragInfo Yes Information about the drag point.
itemIndex number Yes Index of the dragged element.

Return value

Type Description
CustomBuilder Returns a CustomBuilder object for constructing the drag preview of the dragged element. If void is returned, the drag operation cannot be performed.

OnGetPreviewBadgeCallback23+

type OnGetPreviewBadgeCallback = () => boolean | number

Called to obtain the number of selected items when the animation for gathering selected items upon long press is about to start.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 23.

System capability: SystemCapability.ArkUI.ArkUI.Full

Return value

Type Description
boolean | number Whether to display a badge showing the count of selected items on the menu preview image after the animation for gathering selected items upon long press is played, or the specific number to display.
true: The number of selected items in a Grid or List component will be displayed as the badge. false: The badge is not displayed.
If a number is returned, it will be displayed as the badge by default. Value range: [0, 231-1]. If the value is out of the range, it is treated as true.
If a floating-point number is returned, it is rounded down.

ScrollResult12+

Implements a return value object of the OnWillScrollCallback callback.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
offsetRemain number No No Amount by which the component is about to be scrolled, in vp.

ChildrenMainSize12+

Provides the size information of the child components of the List or ListItemGroup component along the main axis. This object only supports one-to-one binding to the List or ListItemGroup component.

NOTE

  • The main axis size information must match the actual main axis size of the child components. When child components' main axis sizes change or components are added or removed, the ChildrenMainSize object methods must be invoked to notify the List or ListItemGroup component.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

constructor12+

constructor(childDefaultSize: number)

A constructor used to create a ChildrenMainSize object.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
childDefaultSize number Yes Default size of the child component along the main axis.
Unit: vp
NOTE
The value must be a finite non-negative number; otherwise, an exception will be thrown.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.

childDefaultSize12+

set childDefaultSize(value: number)

Sets the default size of the child component along the main axis.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value number Yes Default size of the child component along the main axis.
Unit: vp
NOTE
The value must be a finite non-negative number; otherwise, an exception will be thrown.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.

get childDefaultSize(): number

Obtains the default size of the child component along the main axis.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Return value

Type Description
number Default size of the child component along the main axis.
Unit: vp
Value range: [0, +∞)

splice12+

splice(start: number, deleteCount?: number, childrenSize?: Array<number>): void

Performs batch operations to add, delete, or modify the size information of child components along the main axis.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
start number Yes Index starting from 0, which indicates the position at which to begin modifying the size information of child components along the main axis.
NOTE
1. The value must be a finite non-negative number; otherwise, an exception will be thrown.
2. Non-integer values are truncated to the nearest integer.
3. Values exceeding the maximum index do not take effect.
Value range: [0, +∞)
deleteCount number No Number of size information entries to be deleted starting from the start position.
NOTE
1. The value must be a finite non-negative number; otherwise, it will be treated as 0.
2. Non-integer values are truncated to the nearest integer.
3. The result of (start + deleteCount - 1) can exceed the maximum index, which will delete all size information of child components starting from the start position.
Default value: +∞
Value range: [0, +∞)
childrenSize Array<number > No Size information of all child components to be inserted, starting from the start position.
Unit for each value in the array: vp
NOTE
1. If the values in the array are finite non-negative number, they are considered specified sizes and will not change with the default size.
2. If the values in the array are not finite non-negative number, they will be treated as the default size and will change with the default size.
The default value is an empty array.
Value range: [0, +∞)

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.

NOTE

  • If only the start parameter is used, it means to delete the size information of the child components starting from the start position and beyond.
  • If only the start and deleteCount parameters are used, it means to delete the deleteCount-specified number of size information entries starting from the start position. This is generally used when you remove child components.
  • If all three parameters are used, it means to delete the deleteCount-specified number of size information entries starting from the start position, and then insert all the size information from childrenSize at the start position. This is generally used when you add child components or batch update the main axis size of child components. If it's only about adding child components, deleteCount should be 0, and the number of elements in childrenSize should be equal to the number of child components being added. If it's only about batch updating the main axis size of child components, the number of elements in childrenSize should be equal to deleteCount, which is the number of updates being made.
  • If you want to notify that the size of a child component should be the default size, the corresponding value in childrenSize should not be given as a finite non-negative value, but rather as NaN, any negative value, or any other value that can be processed as the default size.

update12+

update(index: number, childSize: number): void

Updates the main axis size information of the child component corresponding to the specified index.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
index number Yes Index starting from 0, which indicates the position at which to begin modifying the size information of child components along the main axis.
NOTE
1. The value must be a finite non-negative number; otherwise, an exception will be thrown.
2. Non-integer values are truncated to the nearest integer.
3. Values exceeding the maximum index do not take effect.
Value range: [0, +∞)
childSize number Yes Size to be updated to.
Unit: vp
NOTE
1. If the value is a finite non-negative number, it is considered a specified size and will not change with the default size.
2. If the value is not a finite non-negative number, it will be processed as the default size and will change with the default size.
Value range: [0, +∞)

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.

UIScrollableCommonEvent19+

Configures scroll event callbacks.

setOnReachStart19+

setOnReachStart(callback: Callback<void> | undefined): void

Sets the callback for the onReachStart event.

If the input parameter of an API is undefined, the corresponding event callback is reset.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void>  | undefined Yes Callback for the onReachStart event.

setOnReachEnd19+

setOnReachEnd(callback: Callback<void> | undefined): void

Sets the callback for the onReachEnd event.

If the input parameter is undefined, the event callback is reset.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void>  | undefined Yes Callback for the onReachEnd event.

setOnScrollStart19+

setOnScrollStart(callback: Callback<void> | undefined): void

Sets the callback for the onScrollStart event.

If the input parameter is undefined, the event callback is reset.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void>  |  undefined Yes Callback for the onScrollStart event.

setOnScrollStop19+

setOnScrollStop(callback: Callback<void> | undefined): void

Sets the callback for the onScrollStop event.

If the input parameter is undefined, the event callback is reset.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void>  | undefined Yes Callback for the onScrollStop event.

setOnScrollFrameBegin19+

setOnScrollFrameBegin(callback: OnScrollFrameBeginCallback | undefined): void

Sets the callback for the onScrollFrameBegin event.

If the input parameter is undefined, the event callback is reset.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback OnScrollFrameBeginCallback | undefined Yes Callback for the onScrollFrameBegin event.

OnWillStopDraggingCallback20+

type OnWillStopDraggingCallback = (velocity: number) => void

Defines the callback invoked when the scrollable component is released.

Widget capability: This API can be used in ArkTS widgets since API version 20.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
velocity number Yes Scroll velocity. Positive for scrolling upward, negative for scrolling downward.
Unit: vp/s.

OnDidStopDraggingCallback21+

type OnDidStopDraggingCallback = (willFling: boolean) => void

Defines the callback invoked when the scrollable component stops being dragged.

Widget capability: This API can be used in ArkTS widgets since API version 21.

Atomic service API: This API can be used in atomic services since API version 21.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
willFling boolean Yes Whether an inertial animation will follow. true: An inertial animation will follow. false: No inertial animation will follow.

OnVisibleIndexesChangeCallback

type OnVisibleIndexesChangeCallback = (start: number, end: number) => void

Called when the index of the child component displayed in the LazyColumnLayout component changes.

NOTE

  • If LazyColumnLayout has no child components, both start and end return -1.
  • If LazyColumnLayout has no child components in the visible area, both start and end return -1.

Since: 26.0.0

Atomic service API: This API can be used in atomic services since API version 26.0.0.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
start number Yes Index of the start position in the visible area.
Value range: [0, total number of child nodes - 1].
end number Yes Index of the end position in the visible area.
Value range: [0, total number of child nodes - 1].

Example

Example 1: Implementing Gesture-based Scrolling

This example configures the enableScrollInteraction attribute to enable gesture-based scrolling in a vertical list, with index callbacks triggered during page transitions.

For details about ListDataSource and the complete code, see Example 1: Adding a Scroll Event.

// xxx.ets
import { ListDataSource } from './ListDataSource';

@Entry
@Component
struct ListExample {
  private arr: ListDataSource = new ListDataSource([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

  build() {
    Column() {
      List({ space: 20, initialIndex: 0 }) {
        LazyForEach(this.arr, (item: number) => {
          ListItem() {
            Text('' + item)
              .width('100%')
              .height(100)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .borderRadius(10)
              .backgroundColor(0xFFFFFF)
          }
        }, (item: number) => item.toString())
      }
      .enableScrollInteraction(true)
      .listDirection(Axis.Vertical) // Arrangement direction
      .scrollBar(BarState.Off)
      .friction(0.6)
      .divider({
        strokeWidth: 2,
        color: 0xFFFFFF,
        startMargin: 20,
        endMargin: 20
      }) // Divider between rows
      .edgeEffect(EdgeEffect.Spring) // Set the edge scrolling effect to Spring.
      .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => {
        console.info('first' + firstIndex);
        console.info('last' + lastIndex);
        console.info('center' + centerIndex);
      })
      .onScrollVisibleContentChange((start: VisibleListContentInfo, end: VisibleListContentInfo) => {
        console.info(' start index: ' + start.index +
          ' start item group area: ' + start.itemGroupArea +
          ' start index in group: ' + start.itemIndexInGroup);
        console.info(' end index: ' + end.index +
          ' end item group area: ' + end.itemGroupArea +
          ' end index in group: ' + end.itemIndexInGroup);
      })
      .onDidScroll((scrollOffset: number, scrollState: ScrollState) => {
        console.info(`onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset);
      })
      .width('90%')
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}

en-us_image_0000001174264378

Example 2: Setting Edge Fading

This example demonstrates how to use fadingEdge to implement a List component with an edge fading effect and set the length of the fading edge.

For details about ListDataSource and the complete code, see Example 1: Adding a Scroll Event.

// xxx.ets
import { LengthMetrics } from '@kit.ArkUI';
import { ListDataSource } from './ListDataSource';

@Entry
@Component
struct ListExample {
  private arr: ListDataSource = new ListDataSource([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
  scrollerForList: Scroller = new Scroller();

  build() {
    Column() {

      List({ space: 20, initialIndex: 0, scroller: this.scrollerForList }) {
        LazyForEach(this.arr, (item: number) => {
          ListItem() {
            Text('' + item)
              .width('100%')
              .height(100)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .borderRadius(10)
              .backgroundColor(0xFFFFFF)
          }
        }, (item: number) => item.toString())
      }
      .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(80) })
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}

fadingEdge_list

Example 3: Setting the Clipping Region

This example demonstrates how to use the clipContent attribute to modify the clipping region of the component's content layer.

// xxx.ets
import { LengthMetrics } from '@kit.ArkUI';

@Entry
@Component
struct ScrollExample {
  scroller: Scroller = new Scroller();
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
  @State clipContent: ContentClipMode | RectShape | undefined = undefined;

  build() {
    Column() {
      Scroll(this.scroller) {
        Column() {
          ForEach(this.arr, (item: number) => {
            Text(item.toString())
              .width(300)
              .height(80)
              .fontSize(20)
              .textAlign(TextAlign.Center)
              .backgroundColor(Color.Grey)
          }, (item: string) => item)
        }
      }
      .backgroundColor(Color.Blue)
      .clipContent(this.clipContent)
      .scrollBar(BarState.Off)
      .friction(0.6)
      .width(300)
      .height('50%')
      .padding(10)
      .safeAreaPadding(LengthMetrics.vp(10))
      .initialOffset({ yOffset: 80 })
      .margin({ top: 20 })

      Button('clipContent SAFE_AREA')
        .onClick(() => {
          this.clipContent = ContentClipMode.SAFE_AREA;
        }).margin({ top: 30 })

      Button('clipContent BOUNDARY')
        .onClick(() => {
          this.clipContent = ContentClipMode.BOUNDARY;
        }).margin({ top: 35 })

      Button('clipContent CONTENT_ONLY')
        .onClick(() => {
          this.clipContent = ContentClipMode.CONTENT_ONLY;
        }).margin({ top: 40 })
    }.width('100%').height('100%').backgroundColor(0xDCDCDC)
  }
}

clipContent_scroll

Example 4: Setting the Scrollbar Margin

This example demonstrates how to use the scrollBarMargin attribute to adjust the scrollbar margins of a scrollable component, available since API version 20.

For details about ListDataSource and the complete code, see Example 1: Adding a Scroll Event.

// xxx.ets
import { ListDataSource } from './ListDataSource';
import { LengthMetrics } from '@kit.ArkUI';

@Entry
@Component
struct ListExample {
  arr: ListDataSource = new ListDataSource([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
  @State scrollBarMargin: ScrollBarMargin = { start: LengthMetrics.vp(0), end: LengthMetrics.vp(0) };

  build() {
    Stack({ alignContent: Alignment.TopStart }) {
      Column() {
        List({ space: 20, initialIndex: 0 }) {
          LazyForEach(this.arr, (item: number, index?: number) => {
            ListItem() {
              Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
                Text('' + item)
                  .width('100%')
                  .height(80)
                  .fontSize(20)
                  .textAlign(TextAlign.Center)
                  .borderRadius(10)
                  .backgroundColor(Color.White)
                  .flexShrink(1)
              }
            }
          }, (item: number) => item.toString())
        }.width('90%')
        .friction(0.6)
        .scrollBar(BarState.On)
        .scrollBarMargin(this.scrollBarMargin)
      }.width('100%')

      Button('scrollBarMargin')
        .onClick(() => {
          this.scrollBarMargin = { start: LengthMetrics.vp(45), end: LengthMetrics.vp(70) };
        }).margin({ top: 5, left: 20 })

      Button('scrollBarMargin2')
        .onClick(() => {
          this.scrollBarMargin = { start: LengthMetrics.vp(15), end: LengthMetrics.vp(100) };
        }).margin({ top: 200, left: 20 })
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  }
}

scrollBarMargin_list