Tgo1014
06/13/2022, 11:25 PMscrollBy
the PositionIndicator
is not shown but if you use animateScrollBy
instead, it shows (at least when calling inside the onPreRotaryScrollEvent{}
. I'll post the code to reproduce on the 🧵Tgo1014
06/13/2022, 11:26 PM@Composable
fun WearApp() {
MyApplicationTheme {
val listState = rememberScalingLazyListState()
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) { focusRequester.requestFocus() }
Scaffold(positionIndicator = { PositionIndicator(scalingLazyListState = listState) }) {
ScalingLazyColumn(
state = listState,
modifier = Modifier
.fillMaxSize()
.scrollableColumnWithHaptics(focusRequester, listState),
) { items(100) { Text("Test") } }
}
}
}
@OptIn(ExperimentalComposeUiApi::class)
fun Modifier.scrollableColumnWithHaptics(
focusRequester: FocusRequester,
scrollableState: ScrollableState,
): Modifier = composed {
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
val vibrator = remember { context.getSystemService(Vibrator::class.java) }
onPreRotaryScrollEvent {
coroutineScope.launch {
if (!scrollableState.isScrollInProgress) {
vibrator?.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK))
}
scrollableState.animateScrollBy(it.verticalScrollPixels)
}
true
}
.focusRequester(focusRequester)
.focusable()
}
John Nichol
06/14/2022, 7:37 AMyschimke
06/23/2022, 12:57 PMyschimke
06/23/2022, 12:58 PManimateScrollBy(0f)
yschimke
06/23/2022, 12:58 PMpublic fun Modifier.scrollableColumn(
focusRequester: FocusRequester,
scrollableState: ScrollableState
): Modifier = composed {
val coroutineScope = rememberCoroutineScope()
onPreRotaryScrollEvent {
coroutineScope.launch {
scrollableState.scrollBy(it.verticalScrollPixels)
scrollableState.animateScrollBy(0f)
}
true
}
.focusRequester(focusRequester)
.focusable()
}
yschimke
06/23/2022, 12:59 PM