google / horologist

Horologist is a group of libraries that aim to supplement Wear OS developers with features that are commonly required by developers but not yet available.
https://google.github.io/horologist/
Apache License 2.0
571 stars 94 forks source link

rotaryWithScroll not working with ScalingLazyColumn #2008

Closed AdrianDev0 closed 9 months ago

AdrianDev0 commented 9 months ago

Hi, I created a very basic sample with a ScalingLazyColumn using rotaryWithScroll to be able to scroll via the crown/RSB. But if I rotate the RSB, the list isn't scrolling. I also tried it with onRotaryScrollEvent which is suggested here which works. So is it intended to use the old onRotaryScrollEvent or is rotaryWithScroll with ScalingLazyColumn just not working correctly? Or am I doing sth. wrong here?

Used on Pixel Watch with Wear OS 4 and Horologist 0.5.14

@OptIn(ExperimentalHorologistApi::class)
@Composable
fun WearApp() {
    MyApplicationTheme {

        val scrollState = rememberScalingLazyListState()
        val focusRequester = rememberActiveFocusRequester()
        LaunchedEffect(Unit) {
            focusRequester.requestFocus()
        }

        ScalingLazyColumn(
            modifier = Modifier
                .fillMaxWidth()
                .rotaryWithScroll(
                    focusRequester = focusRequester,
                    scrollableState = scrollState,
                ),
        ) {
            items(List(100) {i -> "$i"}) {
                Box(modifier = Modifier
                    .fillMaxWidth()
                    .height(50.dp),) {
                    Text(text = it)
                }
            }
        }
    }
}
yschimke commented 9 months ago

You need to pass the scrollState into the ScalingLazyColumn.

Also you don't need the LaunchedEffect. rememberActiveFocusRequester is enough.