smoothScroll
Function
Common
fun MouseInjectionScope.smoothScroll(
scrollAmount: Float,
durationMillis: Long = DefaultMouseGestureDurationMillis,
scrollWheel: ScrollWheel = ScrollWheel.Vertical,
)
Rotate the mouse's scrollWheel
by the given scrollAmount
. The total scroll delta is linearly
smoothed out over a stream of scroll events between each scroll event.
Positive scrollAmount
values correspond to scrolling forward (new content appears at the bottom
of a column, or at the end of a row), negative values correspond to scrolling backward (new
content appears at the top of a column, or at the start of a row).
Example of a horizontal smooth scroll:
Parameters
scrollAmount | The total delta to scroll the scrollWheel by |
durationMillis | The duration of the gesture. By default 300 milliseconds. |
scrollWheel | Which scroll wheel will be rotated. By default ScrollWheel.Vertical . |
Code Examples
mouseInputSmoothScroll
fun mouseInputSmoothScroll() {
composeTestRule.onNodeWithTag("horizontalScrollable").performMouseInput {
// Scroll forwards horizontally, which is rightwards
// unless scroll direction is reversed
smoothScroll(100f, durationMillis = 500L, ScrollWheel.Horizontal)
// The 100f scroll delta is equally divided into smaller scrolls,
// such that the time in between two scroll events is more or less
// equal to the default time between events, 16ms.
}
}