force menu invalidation when expanding actionView from user interaction to properly layout menu items (#2503)
This commit is contained in:
@@ -85,10 +85,11 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for disappearing menu items when collapsing an expandable item like a SearchView.
|
||||
* Workaround for buggy menu item layout after expanding/collapsing an expandable item like a SearchView.
|
||||
* This method should be removed when fixed upstream.
|
||||
* Issue link: https://issuetracker.google.com/issues/37657375
|
||||
*/
|
||||
var expandActionViewFromInteraction = false
|
||||
fun MenuItem.fixExpand(onExpand: ((MenuItem) -> Boolean)? = null, onCollapse: ((MenuItem) -> Boolean)? = null) {
|
||||
setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||
@@ -101,6 +102,25 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
|
||||
return onCollapse?.invoke(item) ?: true
|
||||
}
|
||||
})
|
||||
|
||||
if (expandActionViewFromInteraction) {
|
||||
expandActionViewFromInteraction = false
|
||||
expandActionView()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for menu items not disappearing when expanding an expandable item like a SearchView.
|
||||
* [expandActionViewFromInteraction] should be set to true in [onOptionsItemSelected] when the expandable item is selected
|
||||
* This method should be called as part of [MenuItem.OnActionExpandListener.onMenuItemActionExpand]
|
||||
*/
|
||||
fun invalidateMenuOnExpand(): Boolean {
|
||||
return if (expandActionViewFromInteraction) {
|
||||
activity?.invalidateOptionsMenu()
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user