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
572 stars 94 forks source link

Documentation for rotaryWithScroll #2457

Open jeantuffier opened 1 day ago

jeantuffier commented 1 day ago

Hi!

I'm trying to use the example from https://google.github.io/horologist/compose-layout/ but I haven't figure out in which dependency rotaryWithScroll is located. I tried horlogist.composables, horlogist.layout and horlogist.materials but it doesn't seem to be there. Could you add a section in the documentation on where to find it?

Thanks

yschimke commented 1 day ago

Ooops, sorry, that needs to be updated. Wear Compose added rotaryScrollable which should be used instead.

@Composable
fun ScrollScreenLazyColumn(scrollState: LazyListState) {
    val focusRequester = rememberActiveFocusRequester()

    LazyColumn(
        modifier = Modifier.rotaryScrollable(
            behavior = behavior(scrollableState = scrollState),
            focusRequester = focusRequester,
        ),
        state = scrollState,
    ) {
        items(3) { i ->
            val modifier = Modifier.fillParentMaxHeight(0.5f)
            ExampleCard(modifier = modifier, i = i)
        }
    }
}
yschimke commented 1 day ago

I'll update the docs before closing this.

yschimke commented 1 day ago

Maybe a better sample for Column

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:wear/compose/integration-tests/demos/src/main/java/androidx/wear/compose/integration/demos/ScrollAwayDemos.kt;l=137?q=rotaryScrollable%20Column

        Column(
            modifier =
                Modifier.verticalScroll(scrollState)
                    .rotaryScrollable(
                        RotaryScrollableDefaults.behavior(
                            scrollableState = scrollState,
                            flingBehavior = ScrollableDefaults.flingBehavior()
                        ),
                        focusRequester = focusRequester
                    )
        ) {
            val modifier = Modifier.height(LocalConfiguration.current.screenHeightDp.dp / 2)
            repeat(10) { i -> ExampleCard(modifier, i) }
        }