A scroll indicator that transitions to indicate that a scroll gesture is available to the user.
@Composable
fun OneHandedGestureTransformingLazyColumnSample() {
val backDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
val onClick =
remember<() -> Unit> { { backDispatcherOwner?.onBackPressedDispatcher?.onBackPressed() } }
val tlcState = rememberTransformingLazyColumnState()
var scrollGestureIndicatorVisible by remember { mutableStateOf(false) }
val interactionSource = remember { MutableInteractionSource() }
ScreenScaffold(
scrollState = tlcState,
edgeButton = {
var buttonGestureIndicatorVisible by remember { mutableStateOf(false) }
EdgeButton(
onClick = onClick,
interactionSource = interactionSource,
modifier =
if (tlcState.canScrollForward) {
Modifier
} else {
// Apply the one-handed gesture modifier only when the container cannot
// scroll further, ensuring the EdgeButton is fully visible and interactive
Modifier.oneHandedGesture(
action = GestureAction.Primary,
priority = GesturePriority.Clickable,
interactionSource = interactionSource,
onShowIndicator = { buttonGestureIndicatorVisible = true },
onGesture = onClick,
)
} then
Modifier.scrollable(
tlcState,
orientation = Orientation.Vertical,
reverseDirection = true,
overscrollEffect = rememberOverscrollEffect(),
),
) {
OneHandedGestureIndicator(
buttonGestureIndicatorVisible,
{ buttonGestureIndicatorVisible = false },
) {
Text("Close")
}
}
},
scrollIndicator = {
OneHandedGestureScrollIndicator(
scrollGestureIndicatorVisible,
onGestureIndicatorFinished = { scrollGestureIndicatorVisible = false },
tlcState,
modifier = Modifier.align(Alignment.CenterEnd),
)
},
) { contentPadding ->
TransformingLazyColumn(
state = tlcState,
contentPadding = contentPadding,
modifier =
Modifier.fillMaxSize()
.oneHandedGesture(
action = GestureAction.Primary,
priority = GesturePriority.Scrollable,
onGesture = { OneHandedGestureDefaults.scrollDown(tlcState) },
onShowIndicator = { scrollGestureIndicatorVisible = true },
),
) {
items(10) { Text("Item $it") }
}
}
}