Search code examples
android-jetpack-composeandroid-tvandroid-jetpack-compose-material3jetpack-compose-navigationandroid-jetpack-compose-lazy-column

How to switch focus from ModalNavigationDrawer to LazyColumn on Android TV using Jetpack Compose?


I am using Jetpack Compose for Android TV. For navigation drawer I use ModalNavigationDrawer. One of items in drawer is Home.

Here are two scenarios:

  • When I press Home in navigation drawer, it opens screen which contains Box with custom item (focus is still on Home in navigation drawer). When I press button right on remote controller, navigation drawer closes and focus goes to the button in custom item. That is test scenario and it works as expected.

  • When I press Home, I actually want to open screen which contains LazyColumn with custom items. When I press button right on remote controller, navigation drawer doesn't close and focus doesn't go to button in custom item. That is not ok. I want behavior as in first scenario, I want navigation drawer to close and switch focus from navigation drawer to button in custom item in LazyColumn.

Custom item persist of image (as background, not focusable) and two buttons (focusable).

Why pressing right button on remote controller doesn't have the same effect when I use Box and LazyColumn? They both have the same child custom item. How to get effect from Box on LazyColumn?


Solution

  • I found solution: you have to set start padding or x offset of LazyColumn on 16.dp or higher and then it works.

    I hope it will help to someone :)