I am using `androidx.compose.material3.SearchBar` ...
# compose-android
t
I am using
androidx.compose.material3.SearchBar
in its expanded state in my Android project. The screenshots shows what happens when a user performs the back gesture. For some reason, the
SearchBar
consumes the back gesture. This prevents the user from leaving the screen at all. How can this be fixed? https://stackoverflow.com/questions/79107654/how-to-fix-onbackpressed-for-an-expanded-material3-searchbar
1
m
Do your composable use the back handler? > Given a parameter in the composable as: > onBack: () -> Unit > ... > BackHandler(onBack = onBack) Check this if any additional help.. https://medium.com/@desilio/searchbar-with-jetpack-compose-and-material-design-3-1f735f383c1f
t
@marlonlom I cannot see that there is
BackHandler
in material3. Can you explain in more detail please?
m
@Tobias Preuss you must import 'import androidx.activity.compose.BackHandler' If you're using version catalog, add this: androidx-activity-compose = "androidx.activityactivity compose1.9.3"
t
@marlonlom Thanks. I found it. I added
BackHandler { onViewEvent(OnBackPress) }
. The callback is not invoked though, when I perform the BACK gesture.
👏🏼 1
r
Had this issue yesterday and have fixed it after playing with consuming the onExpendedChange callback for updating my hiosted expended value. The internal DockedSearchBar's BackHandler will be ignored if expended became
false
t
@marlonlom Resolved You were right. I checked again with a fresh mind and now it works as expected. See my answer on SO. Thank you 🙌
108 Views