❤️ A heart-shaped toggle switch component built using Jetpack Compose

Overview
heart-switch Demo

heart-switch

A heart-shaped toggle switch component built using Jetpack Compose. Inspired by Tore Bernhoft's I heart toggle Dribbble shot and Anatoliy Gatt's React component.


Getting Started

Release

Add the following code to your project's root build.gradle file:

repositories {
    maven { url "https://jitpack.io" }
}

Next, add the dependency below to your module's build.gradle file:

dependencies {
    implementation "com.github.popovanton0:heart-switch:LATEST_VERSION"
}

Usage

Examples are in the source code.

Basic

@Composable
fun BasicUsage() {
    var state by remember { mutableStateOf(true) }
    HeartSwitch(
        checked = state,
        onCheckedChange = { state = it },
    )
}

Basic Usage Preview

Advanced

@Composable
fun AdvancedUsage() {
    var state by remember { mutableStateOf(true) }
    HeartSwitch(
        checked = state,
        onCheckedChange = { state = it },
        modifier = Modifier,
        colors = HeartSwitchColors(
            checkedTrackColor = Color(0xFFE91E63),
            checkedTrackBorderColor = Color(0xFFC2185B),
            uncheckedTrackBorderColor = Color(0xFFBDBDBD)
        ),
        width = 34.dp,
        borderWidth = 2.1.dp,
        movementAnimSpec = spring(stiffness = Spring.StiffnessMediumLow),
        colorsAnimSpec = spring(stiffness = Spring.StiffnessMediumLow),
        thumb = { modifier, color ->
            Box(
                modifier = modifier
                    .shadow(12.dp, CircleShape)
                    .background(color.value, CircleShape)
            )
        },
        enabled = true,
        interactionSource = remember { MutableInteractionSource() },
    )
}

Advanced Usage Preview

You can customize colors using HeartSwitchColors class:

data class HeartSwitchColors(
    val checkedThumbColor: Color = Color.White,
    val checkedTrackColor: Color = Color(0xffff708f),
    val checkedTrackBorderColor: Color = Color(0xffff4e74),
    val uncheckedThumbColor: Color = Color.White,
    val uncheckedTrackColor: Color = Color.White,
    val uncheckedTrackBorderColor: Color = Color(0xffd1d1d1),
)

And, you even can fully customize thumb's appearance using thumb composable param. Default implementation is:

@Composable
fun Thumb(modifier: Modifier, color: State<Color>) = Box(
    modifier = modifier
        .shadow(6.dp, CircleShape)
        .background(color.value, CircleShape)
) 
You might also like...
Jetpack Compose component box.
Jetpack Compose component box.

Jetpack Compose Component Box About The Project ℹ️ This project is a project where you can find and use custom components in Jetpack Compose. Our goal

A Jetpack Compose component used for displaying Markdown-formatted text.
A Jetpack Compose component used for displaying Markdown-formatted text.

MarkdownText A library for displaying Markdown contents within Jetpack Compose. Uses Coil Current limitations Lists that are annotated with the * must

JetFlix - A clone of Android NetFlix app in Android built using Jetpack compose.
JetFlix - A clone of Android NetFlix app in Android built using Jetpack compose.

JetFlix A clone of Android NetFlix app in Android built using Jetpack compose. This sample app showcases the following: MVVM Architecture (ViewModel +

This app can be used to track open slots for vaccination. This is built using Jetpack Compose.
This app can be used to track open slots for vaccination. This is built using Jetpack Compose.

Covid Vaccine This projects used the Cowin APIs provided by the government. Screenshots Tech Stack Used Kotlin Dagger Hilt Clean Architecture with Mod

🧱  A tetris game fully built using Jetpack Compose
🧱 A tetris game fully built using Jetpack Compose

A tetris game fully built using Jetpack Compose, almost all UI elements are created by code, including the following app icon, which is also generated by Composable with @Preview.

This is a sample app(For beginners - App #1) built using Jetpack Compose
This is a sample app(For beginners - App #1) built using Jetpack Compose

This is a sample app(For beginners - App #1) built using Jetpack Compose. It is a simple - single screen app to demonstrate use of basic Jetpack Compose UI elements like Text, Image and Button & LazyColumn (Vertical Recyclerview). It also demonstrates how compose manages state with a Boolean State.

An android library to highlight different features of the app built using Jetpack Compose.
An android library to highlight different features of the app built using Jetpack Compose.

An android library to highlight different features of the app built using Jetpack Compose.

LearnCompose - A simple UI built using Jetpack Compose
LearnCompose - A simple UI built using Jetpack Compose

Compose course UI A simple UI built using Jetpack Compose. Consists of a list sc

Facebook clone built using Jetpack Compose, Firebase Authentication and Firebase Firestore.

facebook-compose Facebook clone built using Jetpack Compose, Firebase Authentication and Firebase Firestore. Setup Create a Firebase project and add t

Releases(1.2.0)
Owner
Anton Popov
Android Developer
Anton Popov
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

BHAVNA THACKER 3 Dec 31, 2022
Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop 🚀, using Canvas API 🎨

?? ?? ?? Compose flocking Ants(boids) ?? ?? ?? Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop ?? , usi

Chetan Gupta 38 Sep 25, 2022
A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose

Authentication A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose Scree

Felix Kariuki 5 Dec 29, 2022
Android Clean Architecture with MVVM using Jetpack component

Android Clean Architecture with MVVM using Jetpack component ?? What is Clean Architecture? Clean architecture is a category of software design patter

Jbsolutions 6 Dec 10, 2022
🗻 Unopinionated, easy-to-use, and customizable Badge component for Jetpack Compose

Cobadge ?? Unopinionated, easy-to-use, and customizable Badge component for Jetpack Compose Getting started In this section I will walk you through th

Michael Grigoryan 5 Jun 28, 2022
Kotlin, MVVM, Navigation Component, Hilt, Jetpack Compose, Retrofit2

What is this project? This course will replace my old java mvvm introduction: https://codingwithmitch.com/courses/rest-api-mvvm-retrofit2/. Watch the

Mitch Tabian 452 Jan 1, 2023
ComposeImageBlurhash is a Jetpack Compose component with the necessary implementation to display a blurred image while the real image is loaded from the internet. Use blurhash and coil to ensure good performance.

compose-image-blurhash ComposeImageBlurhash is a Jetpack Compose component with the necessary implementation to display a blurred image while the real

Orlando Novas Rodriguez 24 Nov 18, 2022
Android Sample Kotlin+ MVI + Jetpack compose + Coroutines + Retrofit + Hilt + Room + Navigation component

MVIComposeSample Android Sample app to show user latest movies implementing MVI + Clean Architecture using kotlin & Jetpack compose following solid an

Ahmed Atwa 10 Dec 28, 2022
Icontent - Jetpack Compose component to show all random content sended by Inmersoft guide backend

icontent IContent is a library that allows loading audio visual content generica

Orlando Novas Rodriguez 3 Nov 3, 2022
A Coordinator Layout-like component in Jetpack Compose.

CollapsingToolbarInCompose Branches master: Initial code. column_version: Resulting code using a Column. ?? lazycolumn_version: Resulting code using a

Glenn 38 Dec 9, 2022