Repository: android/compose-samples
File: Jetsnack/app/src/main/java/com/example/jetsnack/ui/home/Home.kt (Kotlin)

Code before:
enum class HomeSections(
    @StringRes val title: Int,
    val icon: ImageVector,
    val route: String
) {
    FEED(R.string.home_feed, Icons.Outlined.Home, HomeDestinations.FEED_ROUTE),
    SEARCH(R.string.home_search, Icons.Outlined.Search, HomeDestinations.SEARCH_ROUTE),
    CART(R.string.home_cart, Icons.Outlined.ShoppingCart, HomeDestinations.CART_ROUTE),
    PROFILE(R.string.home_profile, Icons.Outlined.AccountCircle, HomeDestinations.PROFILE_ROUTE)
}

@Composable
fun JetsnackBottomBar(
    navController: NavController,
    tabs: Array<HomeSections>,
    color: Color = JetsnackTheme.colors.iconPrimary,
    contentColor: Color = JetsnackTheme.colors.iconInteractive
) {

    val navBackStackEntry by navController.currentBackStackEntryAsState()
    val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
        ?: HomeSections.FEED.route

    val routes = remember { HomeSections.values().map { it.route } }
    if (currentRoute in routes) {
        val currentSection = HomeSections.values().first { it.route == currentRoute }
        JetsnackSurface(
            color = color,
            contentColor = contentColor
        ) {
            val springSpec = remember {
                SpringSpec<Float>(
                    // Determined experimentally
                    stiffness = 800f,
                    dampingRatio = 0.8f
                )
            }
            JetsnackBottomNavLayout(
                selectedIndex = currentSection.ordinal,
                itemCount = routes.size,
                indicator = { JetsnackBottomNavIndicator() },
                animSpec = springSpec,
                modifier = Modifier.navigationBarsPadding(left = false, right = false)
            ) {
                tabs.forEach { section ->
                    val selected = section == currentSection
                    val tint by animateColorAsState(
                        if (selected) {
                            JetsnackTheme.colors.iconInteractive
                        } else {
                            JetsnackTheme.colors.iconInteractiveInactive

Review comment (performance):
`HomeSections.values()` will create a new array every composition. Cache the value somewhere (could be a top level val)

Code after:
    PROFILE(R.string.home_profile, Icons.Outlined.AccountCircle, "home/profile")
}

@Composable
fun JetsnackBottomBar(
    navController: NavController,
    tabs: Array<HomeSections>,
    color: Color = JetsnackTheme.colors.iconPrimary,
    contentColor: Color = JetsnackTheme.colors.iconInteractive
) {

    val navBackStackEntry by navController.currentBackStackEntryAsState()
    val currentRoute = navBackStackEntry?.destination?.route

    val sections = remember { HomeSections.values() }
    val routes = remember { sections.map { it.route } }
    if (currentRoute in routes) {
        val currentSection = sections.first { it.route == currentRoute }
        JetsnackSurface(
            color = color,
            contentColor = contentColor
        ) {
            val springSpec = SpringSpec<Float>(
                // Determined experimentally
                stiffness = 800f,
                dampingRatio = 0.8f
            )
            JetsnackBottomNavLayout(
                selectedIndex = currentSection.ordinal,
                itemCount = routes.size,
                indicator = { JetsnackBottomNavIndicator() },
                animSpec = springSpec,
                modifier = Modifier.navigationBarsPadding(left = false, right = false)
            ) {
                tabs.forEach { section ->
                    val selected = section == currentSection
                    val tint by animateColorAsState(
                        if (selected) {
                            JetsnackTheme.colors.iconInteractive
                        } else {
                            JetsnackTheme.colors.iconInteractiveInactive
                        }
                    )

                    JetsnackBottomNavigationItem(
                        icon = {
                            Icon(
                                imageVector = section.icon,
                                tint = tint,
                                contentDescription = null
                            )