Previously I was using <Yuri's solution> for rotar...
# compose-wear
b
Previously I was using Yuri's solution for rotaryInput. However, as wear-compose was raised to beta, that solution did not work. I replaced it with onRotaryScrollEvent and focusRequest, which were added to Alpha-15 in the past, and it seems to work normally now. Please let me know if you have any known issues or better suggestions regarding this.
Copy code
val scope = rememberCoroutineScope()
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
    focusRequester.requestFocus()
}
Modifier
.onRotaryScrollEvent{
   scope.launch{
       scalingLazyListState.scollBy(it.verticalScrollPixels)
   }
   true
}
.focusRequester(focusRequester)
.focusable()
What I additionally found out about this is that focuseRequester() and focasable() must not be above onRotaryScrollEvent{}. • working
Copy code
.onRotaryScrollEvent{
   scope.launch{
       scalingLazyListState.scollBy(it.verticalScrollPixels)
   }
   true
}
.focusRequester(focusRequester)
.focusable()
• not working
Copy code
.focusRequester(focusRequester)
.focusable()
.onRotaryScrollEvent{
   scope.launch{
       scalingLazyListState.scollBy(it.verticalScrollPixels)
   }
   true
}
🙌 1
Copy code
/**
 * Adds Rotary support (for devices that have a rotating bezel) to scrollable screens.
 * The screen containing the scrollable item must request focus as appropriate, usually
 *
 *
* LaunchedEffect(Unit) { * focusRequester.requestFocus() * } *
Copy code
*/
@ExperimentalHorologistComposeLayoutApi
public fun Modifier.scrollableColumn(
    focusRequester: FocusRequester,
    scrollableState: ScrollableState
): Modifier = composed {
    val coroutineScope = rememberCoroutineScope()

    onPreRotaryScrollEvent {
        coroutineScope.launch {
            scrollableState.scrollBy(it.verticalScrollPixels)
        }
        true
    }
        .focusRequester(focusRequester)
        .focusable()
}
❤️ 1
This is available as a library in horologist.
Copy code
implementation "com.google.android.horologist:horologist-compose-layout:0.0.21"
b
@yschimke Thanks. I will refer to the library you told me.
t
@yschimke I just tried your code and it works perfectly with the bezel from galaxy watch 4 but it doesn't have the "haptics" that I've had when scrolling the play store for example. How to achieve it?
y
The reason we don't do that is because eventually the Wear Compose components will do that, and they are tough to get right externally. Lot of effects like a thud at end of list etc.
But as an example if you want to get started the volume control does it.
You can look how this works, and apply to your own adaption of the current code.
If you get something awesome going, please consider a PR to horologiat! Or just share your working if you get stuck
Cc @John Nichol do we know which release most wear compose built in haptics will be coming.
j
We are actively investigating what is needed to improve the built in haptics support. We need to determine whether the changes will go into the Core Compose libraries or into Wear Compose or Wear Platform. So at the moment I can't really say whether we will be able to add any further support in 1.1.
2
t
So in the future the idea is that there's native support for it? Would be great as it seems natural where there's a list to be able to scroll with the bezel, so would be nice to have the option to remove in case it's not needed as opposed to have to implement manually, but I understand the components are improving, so not big deal 😁 I'll take a look in the code you pointed @yschimke and adapt for my case, just asked to make sure I wasn't doing something wrong and missing the haptics. Thanks you both for the weekend answer 😁
1