I'm having focus issues with ComposeView inside a ...
# compose
s
I'm having focus issues with ComposeView inside a RecyclerView (I started with Leanback's VerticalGridView, but to simplify I'm using RecyclerView for now). The problem is that if my ComposeView internally doesn't contain anything focusable (a Text for example), the RecyclerView still moves focus to it when pressing DPAD_DOWN/UP. Obviously this doesn't happen in a pure legacy recyclerview with Buttons and TextViews, so I tried setting
composeView.isFocusable = false
for those cases and that didn't work. I dug in deeper and found that a ComposeView usually has a single child: AndroidComposeView (src), so in my
onBindViewHolder
I put:
Copy code
holder.composeView.doOnAttach {
            (it as ViewGroup).get(0).isFocusable = focusable
        }
And that actually works, but is a terrible hack. Is there a "proper" way to get this to work?
z
Please file a bug. Cc @Ralston Da Silva
r
Yes this looks like a bug. AndroidComposeView reports itself as focusable, but should not take focus when it does not have any focusable children: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]android.kt;drc=a628b756c2710de7e4fc164bffae64eda7f7caa2;l=895 Can you file a bug with the minimal repro you mentioned using recycler view?
a
Hi all, Was there any issue already created for this bug? We are facing a crash due to the same problem. I’ve created a minimal repo to reproduce the crash here and filed a bug here. Let me know if there’s already an existing issue, so I can close this one.
164 Views