Skip to content

TabRow ​

TabRow is a navigation component in Miuix used to create horizontally scrollable tabs. It provides two variants: standard style and contour style, suitable for content categorization and navigation scenarios.

Import ​

kotlin
import top.yukonga.miuix.kmp.basic.TabRow // Standard style
import top.yukonga.miuix.kmp.basic.TabRowWithContour // Contour style

Basic Usage ​

Standard Style ​

kotlin
val tabs = listOf("Recommended", "Following", "Popular", "Featured")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRow(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it }
)

Contour Style ​

kotlin
val tabs = listOf("All", "Photos", "Videos", "Documents")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRowWithContour(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it }
)

Preserve Scroll Position ​

kotlin
val tabs = listOf("Tab 1", "Tab 2", "Tab 3", "Tab 4", "Tab 5")
var selectedTabIndex by remember { mutableStateOf(3) }
val tabListState = rememberLazyListState()

TabRowWithContour(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it },
    listState = tabListState,
)

Properties ​

TabRow Properties ​

Property NameTypeDescriptionDefault ValueRequired
tabsList<String>List of tab texts-Yes
selectedTabIndexIntCurrent selected tab index-Yes
onTabSelected(Int) -> UnitCallback when tab is selected-Yes
modifierModifierModifier for the tab rowModifierNo
colorsTabRowColorsColor configurationTabRowDefaults.tabRowColors()No
minWidthDpMinimum width of each tabTabRowDefaults.TabRowMinWidthNo
maxWidthDpMaximum width of each tabTabRowDefaults.TabRowMaxWidthNo
heightDpHeight of the tab rowTabRowDefaults.TabRowHeightNo
cornerRadiusDpCorner radius of tabsTabRowDefaults.TabRowCornerRadiusNo
itemSpacingDpSpacing between tabs9.dpNo
contentAlignmentAlignmentAlignment of tab contentAlignment.CenterNo
listStateLazyListState?External scroll state for tabsnullNo
interactionSourceMutableInteractionSource?Interaction source for tab itemsnullNo
indicationIndication?Indication for tab itemsnullNo

TabRowWithContour Properties ​

Property NameTypeDescriptionDefault ValueRequired
tabsList<String>List of tab texts-Yes
selectedTabIndexIntCurrent selected tab index-Yes
onTabSelected(Int) -> UnitCallback when tab is selected-Yes
modifierModifierModifier for the tab rowModifierNo
colorsTabRowColorsColor configurationTabRowDefaults.tabRowColors()No
minWidthDpMinimum width of each tabTabRowDefaults.TabRowWithContourMinWidthNo
maxWidthDpMaximum width of each tabTabRowDefaults.TabRowWithContourMaxWidthNo
heightDpHeight of the tab rowTabRowDefaults.TabRowWithContourHeightNo
cornerRadiusDpCorner radius of tabsTabRowDefaults.TabRowWithContourCornerRadiusNo
itemSpacingDpSpacing between tabs5.dpNo
contentAlignmentAlignmentAlignment of tab contentAlignment.CenterNo
listStateLazyListState?External scroll state for tabsnullNo
interactionSourceMutableInteractionSource?Interaction source for tab itemsnullNo
indicationIndication?Indication for tab itemsnullNo

TabRowDefaults Object ​

The TabRowDefaults object provides default configurations for the TabRow component.

Constants ​

Constant NameTypeValueDescription
TabRowHeightDp42.dpDefault height of tab row for standard style
TabRowWithContourHeightDp45.dpDefault height of tab row for contour style
TabRowCornerRadiusDp12.dpDefault corner radius for standard style
TabRowWithContourCornerRadiusDp8.dpDefault corner radius for contour style
TabRowMinWidthDp76.dpMin width of tabs for standard style
TabRowWithContourMinWidthDp62.dpMin width of tabs for contour style
TabRowMaxWidthDp98.dpMax width of tabs for standard style
TabRowWithContourMaxWidthDp84.dpMax width of tabs for contour style

Methods ​

Method NameTypeDescription
tabRowColors()TabRowColorsCreate default color configuration

TabRowColors Class ​

Property NameTypeDescription
backgroundColorColorDefault background color of tabs
contentColorColorDefault content color of tabs
selectedBackgroundColorColorBackground color of selected tab
selectedContentColorColorContent color of selected tab

Advanced Usage ​

Custom Colors ​

kotlin
val tabs = listOf("Latest", "Popular", "Following")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRow(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it },
    colors = TabRowDefaults.tabRowColors(
        backgroundColor = Color.LightGray.copy(alpha = 0.5f),
        contentColor = Color.Gray,
        selectedBackgroundColor = MiuixTheme.colorScheme.primary,
        selectedContentColor = Color.White
    )
)

Custom Dimensions ​

kotlin
val tabs = listOf("Short Videos", "Live", "Articles")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRowWithContour(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it },
    minWidth = 100.dp,
    height = 50.dp,
    cornerRadius = 15.dp
)

Using with Pager ​

kotlin
val tabs = listOf("Page 1", "Page 2", "Page 3")
val pagerState = rememberPagerState { tabs.size }
val scope = rememberCoroutineScope()

Surface {
    Column {
        TabRow(
            tabs = tabs,
            selectedTabIndex = pagerState.currentPage,
            onTabSelected = { index ->
                scope.launch { pagerState.animateScrollToPage(index) }
            }
        )
        HorizontalPager(
            state = pagerState,
            modifier = Modifier.fillMaxSize()
        ) { page ->
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text("Page Content ${page + 1}")
            }
        }
    }
}

Changelog

Released under the Apache-2.0 License