A modern, customizable switch component library for Jetpack Compose that provides beautiful animated switches with various styles and configurations, now with multiplatform support!
- Multiple Switch Variants: 10 different switch styles to choose from
- Multiplatform Support: Works on Android, iOS, Web and Desktop
- Smooth Animations: Fluid transitions with customizable duration and easing
- Highly Customizable: Colors, shapes, sizes, and content can be tailored to your needs
- Jetpack Compose Native: Built specifically for Compose with modern UI patterns
- Lightweight: Minimal dependencies and optimized performance
- Material Design 3: Follows Material Design guidelines and theming
- Platform Native Switches: Use platform-specific native switch implementations
- TextSwitch - Switch with customizable text labels
- ColoredSwitch - Simple colored switch with border
- ISwitch - iOS-style switch with circular thumb
- IconISwitch - iOS-style switch with custom icons
- CustomISwitch - iOS-style switch with custom content
- CustomSwitch - Fully customizable switch with custom content
- SquareSwitch - Modern square-style switch
- NativeSwitch - Platform-specific native switch implementation (Material3 on Android, UIKit on iOS)
- Kotlin - 100% Kotlin
- Jetpack Compose - Modern Android UI toolkit
- Material Design 3 - Latest Material Design components
- Compose Animation - Smooth and performant animations
- Gradle Version Catalogs - Modern dependency management
The library is available on Maven Central. No additional repository setup is required.
dependencies {
implementation("dev.muazkadan:switchy-compose:0.7.2")
}commonMain.dependencies {
implementation("dev.muazkadan:switchy-compose:0.7.2")
}Option 2: JitPack (Legacy)
Add the JitPack repository to your project's settings.gradle file:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}Or in your project-level build.gradle file:
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation("com.github.muazkadan:switchy-compose:0.7.2")
}@Composable
fun MyScreen() {
var switchValue by remember { mutableStateOf(false) }
ISwitch(
checked = switchValue,
onCheckedChange = { switchValue = it }
)
}var switchValue by rememberSaveable { mutableStateOf(false) }
TextSwitch(
modifier = Modifier.padding(horizontal = 16.dp),
checked = switchValue,
positiveText = "ON",
negativeText = "OFF",
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
ColoredSwitch(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
checked = switchValue,
positiveColor = Color.Green,
negativeColor = Color.Red,
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
ISwitch(
checked = switchValue,
buttonHeight = 40.dp,
positiveColor = Color(0xFF35C759),
negativeColor = Color(0xFFE9E9EA),
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
IconISwitch(
checked = switchValue,
positiveIcon = Icons.Default.Done,
negativeIcon = Icons.Default.Close,
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
CustomISwitch(
checked = switchValue,
positiveContent = {
Icon(
imageVector = Icons.Default.Done,
contentDescription = null,
tint = Color.White
)
},
negativeContent = {
Text(
text = "OFF",
color = Color.Gray,
fontSize = 10.sp
)
},
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
CustomSwitch(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
checked = switchValue,
positiveContent = {
Icon(
imageVector = Icons.Default.Done,
contentDescription = null
)
},
negativeContent = {
Text("OFF")
},
onCheckedChange = { switchValue = it }
)var switchValue by rememberSaveable { mutableStateOf(false) }
SquareSwitch(
modifier = Modifier.padding(horizontal = 16.dp),
checked = switchValue,
shape = RoundedCornerShape(4.dp),
onCheckedChange = { switchValue = it }
)var checked by rememberSaveable { mutableStateOf(false) }
NativeSwitch(
checked = checked,
onCheckedChange = { checked = it },
modifier = Modifier.padding(horizontal = 16.dp),
enabled = true
)modifier: Modifier for the switchswitchValue: Current state of the switchonValueChanged: Callback when switch state changesshape: Custom shape for the switchpositiveColor/negativeColor: Colors for different states
buttonHeight: Height of the switch buttoninnerPadding: Padding inside the switch thumbpositiveContent/negativeContent: Custom composable content
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Have an awesome custom Compose switch you'd like to share? We'd love to include it in Switchy Compose! Whether it's a unique animation, a creative design, or a platform-specific style, your custom switch could enhance the library. To contribute:
- Ensure your switch is built with Jetpack Compose and follows Kotlin coding conventions.
- Provide a clear API for your switch, similar to existing variants (e.g.,
TextSwitch,ISwitch). - Include documentation and a demo in the
appmodule to showcase your switch. - Submit a Pull Request with your implementation, and we'll review it for inclusion.
The project includes a demo app showcasing all switch variants. To run the demo:
- Clone the repository
- Open in Android Studio
- Run the
appmodule
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow Kotlin coding conventions
- Add tests for new features
- Update documentation as needed
- Ensure all existing tests pass
Copyright 2023 Muaz KADAN
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- Built with Jetpack Compose
- Kotlin Multiplatform for cross-platform support
- Inspired by iOS switch design patterns
- Published via Maven Central and JitPack
Made with β€οΈ by Muaz KADAN | LinkedIn
