2

They know how to implement the scroll by bezel (Galaxy watch 4 Classic) in wear os 3.0 with jetpack compose

In the documentation it mentions the use of ScalingLazyListState or ScrollState but so far the scroll with the rotating bezel of my device has not been recognized.

if anyone has information or an example it would help me a lot.

enter image description here enter image description here

Alex Bravo
  • 1,601
  • 2
  • 24
  • 40
  • There is a wear-compose slack channel that can help also - https://surveys.jetbrains.com/s3/kotlin-slack-sign-up – Yuri Schimke Nov 22 '21 at 08:38
  • 1
    I was about to provide a sample, but want to confirm it is correct first. It may be out of date https://github.com/joreilly/PeopleInSpace/pull/84/files – Yuri Schimke Nov 22 '21 at 08:46

1 Answers1

2

In Wear Compose Alpha 15, it is now supported.

    val focusRequester = remember { FocusRequester() }

    ScalingLazyColumn(
        modifier = modifier
            .fillMaxSize()
            .onRotaryScrollEvent {
                coroutineScope.launch {
                    scrollState.scrollBy(it.verticalScrollPixels)
                }
                true
            }
            .focusRequester(focusRequester)
            .focusable(),
        state = scrollState,

and then either when the screen is shown, or possible driven by paging (if using HorizontalPager) call requestFocus()

    LaunchedEffect(Unit) {
        focusRequester.requestFocus()
    }
Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Excellent!! it was what you need, thank you very much. – Erick Agüero Nov 23 '21 at 04:38
  • This is now supported in Wear Compose 1.0.0-alpha15, but it also breaks this workaround. – Yuri Schimke Jan 28 '22 at 17:24
  • not working in my case! – Mubashir Murtaza Oct 11 '22 at 13:37
  • It's used extensively in the samples for Horologist https://github.com/google/horologist/blob/75c898a562c9fee37877d8710330a8b7751c7264/compose-layout/src/main/java/com/google/android/horologist/compose/navscaffold/ScrollableColumn.kt So it definitely works. Maybe try the sample apps there and see if it works for you, or it's your device? – Yuri Schimke Oct 12 '22 at 17:03