material-components / material-components/material-components-android
[TabLayout] tabs font is reset to Roboto when attaching new TabLayoutMediator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:** Similar to #965, except not while switching tabs, but resetting tabs with new data after view creation. Using a `StateFlow` in the `Fragment`'s `ViewModel`, which provides data for tabs, when the `StateFlow` receives a new value, attaching a new `TabLayoutMediator` causes the tabs to refresh with the Roboto font instead of the app theme's font. When the tabs are loaded for the first time on view creation, the tabs' font comes from the app theme's `fontFamily` attribute.
**Expected behavior:** The font should be the same theme font, both on the initial tab load and any subsequent refreshes.
**Source code:**
```
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.info.collect { info ->
with(binding) {
tabMediator?.detach()
pager.adapter = InfoAdapter(info)
tabMediator = TabLayoutMediator(tabs, pager, InfoTabConfigurationStrategy(info)).apply {
attach()
}
}
}
}
}
```
**Minimal sample app repro:** Run the app and wait 10 seconds for the tab data refresh. [My Application.zip](https://github.com/material-components/material-components-android/files/9441307/My.Application.zip)
**Android API version:** Android 13 (API 33)
**Material Library version:** 1.6.1 (also 1.7.0-beta01)
**Device:** Pixel 6 Pro
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
Run the linked minimal sample app and reproduce the font reset after the tab data refresh. Start by tracing the TabLayoutMediator attach/detach path used in the provided Fragment code; done means refreshed tabs retain the app theme's fontFamily instead of reverting to Roboto.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100