I'm using a ScrollableTabRow to display some 60 Tabs.
At the very beginning, the indicator should start "in the middle".
However, this results in an unwanted scrolling animation when the composable is drawn - see video. Am i doing something wrong or is this component buggy?
@Composable
@Preview
fun MinimalTabExample() {
val tabCount = 60
var selectedTabIndex by remember { mutableStateOf(tabCount / 2) }
ScrollableTabRow(selectedTabIndex = selectedTabIndex) {
repeat(tabCount) { tabNumber ->
Tab(
selected = selectedTabIndex == tabNumber,
onClick = { selectedTabIndex = tabNumber },
text = { Text(text = "Tab #$tabNumber") }
)
}
}
}
But why would you like to do that? I'm writing a calendar-like application and have a day-detail-view. From there want a fast way to navigate to adjacent days. A Month into the future and a month into the past - relative to the selected month - is what i'm aiming for.

No, you are not doing it wrong. Also the component is not really buggy, rather the behaviour you are seeing is an implementation detail.
If we check the implementation of the
ScrollableTabRowcomposable we see that theselectedTabIndexis used in two places inside the composable:scrollableTableData.onLaidOutcallThe #1 is used for positioning the tabs inside the layout, so it is not interesting for this issue.
The #2 is used to scroll to the selected tab index. The code below shows how the initial scroll state is set up, followed by the call to
scrollableTabData.onLaidOutAnd this is the implementation of the above call
As we can see already from the first comment
but also in the implementation, even the first time the scroll offset is set using an animation.
And the
ScrollableTabRowclass does not expose a way to control this behaviour.