material-components-android
material-components-android copied to clipboard
[SearchView] TransitionListener not work after fragment resume
Description:
I put SearchView in a fragment and hide or show the BottomNavigationView according to the state of the searchview. Once I switch to another fragment and back, the TransitionListener is not called
Expected behavior:
https://github.com/material-components/material-components-android/assets/5838634/4c1674f2-3055-4948-8c4e-401e72542ffb
Source code:
private val transitionListener = SearchView.TransitionListener { _, _, newState ->
Log.w("HomeFragment", "newState: ${newState.name}")
if (newState == SearchView.TransitionState.SHOWING) {
(activity as? MainActivity)?.hideNavView()
} else if (newState == SearchView.TransitionState.HIDDEN) {
(activity as? MainActivity)?.showNavView()
}
}
override fun onResume() {
super.onResume()
searchViewBinding.searchView.addTransitionListener(transitionListener)
}
override fun onPause() {
super.onPause()
searchViewBinding.searchView.removeTransitionListener(transitionListener)
}
Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue. This will help narrow down the conditions required for reproducing the issue, and it will speed up the bug fix process. You may attach a zip file of the sample app or link to a GitHub repo that contains the sample app.
Android API version: 34
Material Library version: 1.11.0
Device: OnePlus 12
It seems that searchview can only be used in activity. If it is placed in fragment, windowinsets will be invalid.