KSwitch - farimarwat/KrossUi GitHub Wiki
KSwitch
Component Documentation
🔘 A multiplatform (Android + iOS) customizable switch component for toggling boolean values.
🔹 Overview
Element | Type | Description |
---|---|---|
KSwitch |
Composable | A switch control for boolean values. |
KSwitch
🧩 Definition:
A composable switch component that allows users to toggle between on/off states. It supports customization of colors and enables/disables interaction.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
modifier |
Modifier |
Modifier |
Modifier for layout and styling. |
checked |
Boolean |
– | Current state of the switch (on/off). |
onCheckedChange |
(Boolean) -> Unit |
– | Callback triggered when switch state changes. |
colors |
KSwitchColors |
KSwitchDefaults.colors() |
Colors for thumb and track depending on state. |
isEnabled |
Boolean |
true |
Whether the switch is enabled or disabled. |
KSwitchColors
🎨 Defines the color configuration for the switch component.
Property | Type | Description |
---|---|---|
thumbColor |
Color |
Color of the switch thumb. |
trackColorChecked |
Color |
Color of the track when the switch is ON. |
trackColorUnchecked |
Color |
Color of the track when the switch is OFF. |
KSwitchDefaults
⚙️ Provides default values and configuration for KSwitch
.
colors(...)
Parameter | Type | Default Value | Description |
---|---|---|---|
thumbColor |
Color |
Color.White |
Color of the thumb. |
trackColorChecked |
Color |
PlatformColors.systemBlue |
Color of the track when checked (ON). |
trackColorUnchecked |
Color |
Color.Gray |
Color of the track when unchecked (OFF). |
Returns a KSwitchColors
instance with the specified or default values.
✅ Usage Example
var switchState by remember { mutableStateOf(true) }
KSwitch(
checked = switchState,
onCheckedChange = {
switchState = it
println("Switch is now: $it")
}
)
🔹 Note:
checked
represents the current ON/OFF state of the switch.onCheckedChange
is triggered whenever the user toggles the switch.- Renders as a native Switch on Android and a Toggle on iOS.