https://kotlinlang.org logo
Title
s

Spiral123

05/24/2021, 9:03 PM
has anyone had experience of enabling list scrolling in compose using a rotary encoder (e.g. twisting a watch crown)? I’m starting to suspect it may not be supported.
z

Zach Klippenstein (he/him) [MOD]

05/24/2021, 9:07 PM
On what platform? Is this like an accessibility service that’s wiring up a watch crown to a phone?
If you’re trying to do this through the accessibility API, support for that isn’t merged yet: https://android-review.googlesource.com/c/platform/frameworks/support/+/1603657
s

Spiral123

05/24/2021, 9:11 PM
exactly. Wear OS. for xml layouts I just add a GenericMotionListener to the view which scales input from the rotary encoder and then scrolls the view: https://developer.android.com/training/wearables/user-input/rotary-input
z

Zach Klippenstein (he/him) [MOD]

05/24/2021, 9:16 PM
I didn’t even realize Compose for wear was usable yet 🙈 But yea if that’s using special events i’m guessing it’s just not wired up yet? There’s some recent work on mouse buttons for compose desktop too i think, i wonder if that will also unblock these other events? Anyhoo, i’m useless here, just speculating.
s

Spiral123

05/24/2021, 9:17 PM
I didn’t even realize Compose for wear was usable yet
we have some simple layouts working - and it looks good. I guess that a GenericMotionListener is not supported yet though. Thanks!
a

Adam Powell

05/24/2021, 9:20 PM
you could probably wire it up using the same sort of strategy used by the back press handler api in androidx.activity; create a dispatcher object, provide it in a CompositionLocal, feed it events by attaching one of the listeners from that training to the ComposeView hosting the UI, write a composable function that adds/removes/manages a listener from composition using DisposableEffect and the provided dispatcher
bingo, your very own
RotaryInputHandler {}
composable
s

Spiral123

05/24/2021, 9:22 PM
@Adam Powell I like the sound of that! not sure I’ll be able to squeeze it into this sprint though lol. Thanks for the suggestion.
👍 1