目录

Scrollable Component Common APIs

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

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

[h2]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

[h2]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 string | number | Color Yes

Scrollbar color.

Default value: '#182431' (40% opacity)

[h2]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 string | number Yes

Scrollbar width.

Default value: 4

Unit: vp

[h2]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 to enable the scroll effect when the component content is smaller than the component itself. The value { alwaysEnabled: true } means to enable the scroll effect, and { alwaysEnabled: false } means the opposite.

Default value:

{ alwaysEnabled: false } for the List, Grid, and WaterFlow components, and { alwaysEnabled: true } for the Scroll component

[h2]nestedScroll11+

nestedScroll(value: NestedScrollOptions): T

Sets the nested scrolling options. You can set 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.

[h2]enableScrollInteraction11+

enableScrollInteraction(value: boolean): T

Sets whether to support scroll gestures. When this attribute is set to false, scrolling by finger or mouse is not supported, but the scroll controller API is not affected.

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.

Default value: true

[h2]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.9 for wearable devices and 0.6 for non-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.

[h2]flingSpeedLimit11+

flingSpeedLimit(speedLimit: number): T

Sets the maximum initial velocity at the start of the fling animation that occurs after gesture-driven scrolling ends. 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
speedLimit number Yes

Maximum initial velocity at the start of the fling animation.

Default value: 12000

Unit: vp/s

Events

[h2]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

[h2]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

[h2]onScrollStart11+

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

Triggered when the scrollable component starts scrolling initiated by the user's finger dragging the component or its scrollbar. This event is also triggered when the animation contained in the scrolling triggered by Scroller starts.

NOTE

  1. This event is triggered when the scrollable component starts to scroll, and it supports various input methods that can initiate the scroll, including keyboard and mouse operations.

  2. This event is triggered when the controller API is called, accompanied by a transition animation.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

[h2]onScrollStop11+

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

Triggered when scrolling stops after the user's finger leaves the screen. This event is also triggered when the animation contained in the scrolling triggered by Scroller stops.

NOTE

  1. The event is triggered when the scrollable component stops scrolling, and it supports various input methods that can initiate the scroll, including keyboard and mouse operations.

  2. This event is triggered when the controller API is called, accompanied by a transition animation.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

[h2]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.

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.

When ScrollEdge and ScrollToIndex that does not involve animation is called, onWillScroll is not invoked.

[h2]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.

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.

[h2]onScroll(deprecated)

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

Triggered when the scrollable component scrolls.

This API is supported since API version 11.

This API is deprecated since API version 12. You are advised to use onDidScroll 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
scrollOffset number Yes

Scroll offset of each 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.

ItemDragInfo

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Description
x number X coordinate of the dragged item, in vp.
y number Y coordinate of the dragged item, in vp.

NestedScrollOptions10+

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Mandatory Description
scrollForward NestedScrollMode Yes Nested scrolling options when the scrollable component scrolls forward.
scrollBackward NestedScrollMode Yes Nested scrolling options when the scrollable component scrolls backward.

EdgeEffectOptions11+

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Mandatory Description
alwaysEnabled boolean Yes Whether to enable the scroll effect when the component content is smaller than the component itself.

OnWillScrollCallback12+

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

Callback 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

Scroll offset of each 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 offset specified by you; returns no ScrollResult object if the component scrolls by the offset specified by scrollOffset in the callback.

OnScrollCallback12+

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

Callback 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

Name Type Mandatory Description
scrollOffset number Yes

Scroll offset of each 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.

ScrollResult12+

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Mandatory Description
offsetRemain number Yes 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.

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

[h2]constructor12+

constructor(childDefaultSize: number): void

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.

[h2]childDefaultSize12+

set childDefaultSize(value: number): void

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 parameter 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

[h2]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.

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.

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. 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.

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 parameter types; 3. Parameter verification failed.
  • 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.

[h2]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.

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. 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.

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 parameter types; 3. Parameter verification failed.