material-components / material-components/material-components-android
[SearchView] TransitionListener not work after fragment resume
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SearchView TransitionListener registration in onResume and removal in onPause, then reproduce the behavior on Android API 34 using the provided source pattern. The payload names no repository files or tests; done means the listener is called correctly after returning to the fragment, with regression coverage added where appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100