rollebonM
rollebonM

Reputation: 196

Compose TextField from Material 3 inside an xml RecycleView item - Cursor is not showing

I tried implementing a jetpack compose text field (e.g. a composable function CustomTextField that makes use of JetpackCompose TextField component from Material 3), and tried to use my composable CustomTextField inside a recycler view item inside my app. As of now, I still haven't tried to reproduce this inside an empty base project.

Surprisingly, I found out that the cursor for the text field is not showing at all, not even when the text field is focused. Other than that, there aren't any other issues.

After investigating the CoreTextField source code, I found out that they have a line like this:

val showCursor = enabled && !readOnly && windowInfo.isWindowFocused && !state.hasHighlight()

After investigating the "windowInfo.isWindowFocused" variable inside my composable CustomTextField, I found out that this variable is always false, even when the composable is focused.

I tried wrapping my CustomTextField with CompositionProvider that provides true for this value, and the cursor started showing once the text field is focused. So, it seems like this was the only condition that prevented the TextField to show the cursor.

To me, this seems like a bug in the jetpack compose/android code. Has anyone encountered an issue like this? Is there something else that I was missing that could have caused this issue.

On my side, I tried experimenting with the view composition strategy for the compose view inside the recycler view item and it didn't make a difference. Nevertheless, the default strategy seems like a good choice for a recycler view item, imho.

Upvotes: 0

Views: 44

Answers (0)

Related Questions