material-components / material-components/material-components-android
[BottomNavigationView] Allow adding menu items without onItemsChanged being called
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
I want to add menu items to BottomNavigationView in code as their configuration is retrieved from the backend.
And that can be done like this:
```
bottomNavigationItems.forEachIndexed { index, item ->
bottomNavigationView.menu.apply {
add(0, item.menuId, index, item.title).apply {
setIcon(item.icon)
}
}
}
```
But when you do that, MenuBuilder.addInternal calls onItemsChanged requesting a relayout after each item is added with is only needed after the last item has been added.
To handle this, MenuBuilder has stopDispatchingItemsChanged.
But BottomNavigationMenu.addInternal prevents this, as it calls startDispatchingItemsChanged internally.
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 BottomNavigationView and the BottomNavigationMenu.addInternal path described in the issue, then inspect how MenuBuilder.stopDispatchingItemsChanged and startDispatchingItemsChanged affect MenuBuilder.addInternal. Done means multiple menu items can be added without requesting a relayout after each addition, while the final addition still updates the navigation view.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100