I found a small bug, if you use `scrollBy` the `Po...
# compose-wear
t
I found a small bug, if you use
scrollBy
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 🧵
👀 1
Copy code
@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()
}
j
@Sergio Sancho
y
@Sergio Sancho gave me a workaround, that appears to work, an
animateScrollBy(0f)
Copy code
public 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()
}
👍🏽 1
I'm not confident it's the right fix.