segmentedcontrol
README.md
SegmentedControl - A Custom Composable UI Component
This SegmentedControl
is a custom Jetpack Compose component designed to display tabs for user selection.
This component is useful for cases where you have a small set of options (2 or 3) that you want to present to
the user in a segmented control fashion.
Features:
- Supports accessibility with proper content descriptions.
- Tab selection indication through indicator color changes.
- Configured to work with 2 or 3 tabs
How to Use:
- Add the necessary imports:
import your.package.name.SegmentedControl
2.Use the SegmentedControl
within your Composable:
` @Composable
fun YourComposableFunction() {
var selectedIndex by remember { mutableStateOf(0) }
val labels = listOf("Option 1", "Option 2")
var selectedTabIndex = remember { mutableStateOf(0)}
`
OCSegmentedControl(
labels = labels,
selectedTabIndex = selectedTabIndex.value,
onSelectedIndexChange = {
selectedTabIndex.value = it
},
initialSelectedTabIndex = 0
) { selectedTabIndex ->
when (selectedTabIndex) {
0 -> {
// Content for Tab 1
Box(modifier = Modifier.fillMaxSize()) {
Text(text = "Tab 1 Content")
}
}
1 -> {
// Content for Tab 2
Column(modifier = Modifier.fillMaxSize()) {
Text(text = "Tab 2 Content")
}
}
}
}
` }`
Parameters:
labels
: A list of strings that represent the tabs. The list size must be between 2 and 3.initialSelectedTabIndex
: An integer indicating initial selected tab index.content
: A composable function which is used to display the content on respective tab click.
Accessibility:
The component supports accessibility with proper content descriptions.
Preview:
Use OCSegmentedControlTwoTabPreview
or OCSegmentedControlThreeTabPreview
Composable function to preview the SegmentedControl