
Beautiful, interactive before/after image slider with horizontal/vertical orientations, customizable thumb/divider/labels, gestures (drag, double‑tap reset, long‑press), hoisted state API and polished defaults.
CompareKit
Before/after image comparison for Kotlin Multiplatform
Maven Central · Install · Quick Start · Changelog · License
A Compose Multiplatform library for interactive before/after image sliders. One composable, Android + iOS, no platform-specific UI code.
Highlights
CompareImageSource
SliderState for full controlPlatforms: Android (minSdk 24), iOS (iosArm64, iosSimulatorArm64)
Add to your shared commonMain dependencies:
implementation("io.github.usmandev0:comparekit:0.1.4")Requirements: Kotlin 2.4+, Compose Multiplatform 1.11.1+
# gradle/libs.versions.toml
[versions]
comparekit = "0.1.4"
[libraries]
comparekit = { module = "io.github.usmandev0:comparekit", version.ref = "comparekit" }// build.gradle.kts
commonMain.dependencies {
implementation(libs.comparekit)
}@Composable
fun PhotoComparison(before: Painter, after: Painter) {
BeforeAfterSlider(
before = before,
after = after,
modifier = Modifier
.fillMaxWidth()
.height(280.dp),
)
}Drag to compare. Starts at 50% by default.
val state = rememberCompareSliderState(initialProgress = 0.5f)
BeforeAfterSlider(
before = before,
after = after,
state = state,
)BeforeAfterSlider(
before = before,
after = after,
cornerRadius = 12.dp,
dividerColor = Color.White,
thumbSize = 40.dp,
beforeLabel = { CompareLabel(text = "Before") },
afterLabel = { CompareLabel(text = "After") },
)BeforeAfterSlider(
orientation = SliderOrientation.Vertical,
before = before,
after = after,
modifier = Modifier.fillMaxWidth().height(240.dp),
)BeforeAfterSlider(
before = before,
after = after,
animationMode = CompareAnimationMode.PingPong,
autoScrubDurationMillis = 2500,
pauseAutoScrubOnInteraction = true,
)| Mode | What it does |
|---|---|
None |
No auto animation (default) |
PingPong |
Loops 0 → 1 → 0 |
RevealOnce |
Animates to after once, then stops |
BeforeAfterSlider(
before = CompareImageSource.url("https://example.com/before.jpg"),
after = CompareImageSource.url("https://example.com/after.jpg"),
)Pinch (or use the scroll wheel) to magnify both images with the same transform. While zoomed, drag the image to pan; drag near the divider to keep comparing. Double-tap resets zoom, then a second double-tap resets the slider.
val zoomState = rememberCompareZoomState(maxScale = 4f)
BeforeAfterSlider(
before = before,
after = after,
zoomEnabled = true,
zoomState = zoomState,
)Pass zoomEnabled = false to keep the original drag-only behavior.
onLongPress callbackBeforeAfterSlider(
before = before,
after = after,
onDoubleTap = { /* reset feedback */ },
onLongPress = { /* action */ },
)The slider exposes progress semantics (progressBarRangeInfo, setProgress, stateDescription) and keyboard support (arrows ± step, Home/End). Images stay decorative; describe them via optional params when needed.
BeforeAfterSlider(
before = before,
after = after,
contentDescription = "Photo retouch comparison",
beforeContentDescription = "Original photo",
afterContentDescription = "Edited photo",
progressStep = 0.05f,
)| API | Purpose |
|---|---|
BeforeAfterSlider |
Main composable |
SliderState |
Hoisted progress (0f–1f) |
rememberCompareSliderState() |
Create slider state |
CompareZoomState |
Shared scale and pan for both images |
rememberCompareZoomState() |
Create zoom state |
CompareAnimationMode |
Auto-scrub modes |
CompareImageSource |
Coil / Painter images |
CompareKitDefaults |
Default styling and a11y values |
Package: com.usmandev.comparekit.beforeafterslider
git clone https://github.com/usmandev0/comparekit.git
cd comparekit
./gradlew :androidApp:installDebugThe demo covers basic usage, Coil loading, customization, labels, gestures, orientation, live controls, auto animation, accessibility, and synced zoom/pan.
| Planned | Status |
|---|---|
| Pinch-zoom and pan | Done |
| Magnifier, video comparison | Planned |
| Desktop & Web targets | Planned |
| Accessibility improvements | Done |
See CHANGELOG.md for release history.
./gradlew :CompareKit:compileAndroidMain
./gradlew :CompareKit:compileKotlinIosSimulatorArm64Apache License 2.0 — see LICENSE.
Author: Usman (@usmandev0)
If CompareKit helps your project, consider starring the repo on GitHub.
CompareKit
Before/after image comparison for Kotlin Multiplatform
Maven Central · Install · Quick Start · Changelog · License
A Compose Multiplatform library for interactive before/after image sliders. One composable, Android + iOS, no platform-specific UI code.
Highlights
CompareImageSource
SliderState for full controlPlatforms: Android (minSdk 24), iOS (iosArm64, iosSimulatorArm64)
Add to your shared commonMain dependencies:
implementation("io.github.usmandev0:comparekit:0.1.4")Requirements: Kotlin 2.4+, Compose Multiplatform 1.11.1+
# gradle/libs.versions.toml
[versions]
comparekit = "0.1.4"
[libraries]
comparekit = { module = "io.github.usmandev0:comparekit", version.ref = "comparekit" }// build.gradle.kts
commonMain.dependencies {
implementation(libs.comparekit)
}@Composable
fun PhotoComparison(before: Painter, after: Painter) {
BeforeAfterSlider(
before = before,
after = after,
modifier = Modifier
.fillMaxWidth()
.height(280.dp),
)
}Drag to compare. Starts at 50% by default.
val state = rememberCompareSliderState(initialProgress = 0.5f)
BeforeAfterSlider(
before = before,
after = after,
state = state,
)BeforeAfterSlider(
before = before,
after = after,
cornerRadius = 12.dp,
dividerColor = Color.White,
thumbSize = 40.dp,
beforeLabel = { CompareLabel(text = "Before") },
afterLabel = { CompareLabel(text = "After") },
)BeforeAfterSlider(
orientation = SliderOrientation.Vertical,
before = before,
after = after,
modifier = Modifier.fillMaxWidth().height(240.dp),
)BeforeAfterSlider(
before = before,
after = after,
animationMode = CompareAnimationMode.PingPong,
autoScrubDurationMillis = 2500,
pauseAutoScrubOnInteraction = true,
)| Mode | What it does |
|---|---|
None |
No auto animation (default) |
PingPong |
Loops 0 → 1 → 0 |
RevealOnce |
Animates to after once, then stops |
BeforeAfterSlider(
before = CompareImageSource.url("https://example.com/before.jpg"),
after = CompareImageSource.url("https://example.com/after.jpg"),
)Pinch (or use the scroll wheel) to magnify both images with the same transform. While zoomed, drag the image to pan; drag near the divider to keep comparing. Double-tap resets zoom, then a second double-tap resets the slider.
val zoomState = rememberCompareZoomState(maxScale = 4f)
BeforeAfterSlider(
before = before,
after = after,
zoomEnabled = true,
zoomState = zoomState,
)Pass zoomEnabled = false to keep the original drag-only behavior.
onLongPress callbackBeforeAfterSlider(
before = before,
after = after,
onDoubleTap = { /* reset feedback */ },
onLongPress = { /* action */ },
)The slider exposes progress semantics (progressBarRangeInfo, setProgress, stateDescription) and keyboard support (arrows ± step, Home/End). Images stay decorative; describe them via optional params when needed.
BeforeAfterSlider(
before = before,
after = after,
contentDescription = "Photo retouch comparison",
beforeContentDescription = "Original photo",
afterContentDescription = "Edited photo",
progressStep = 0.05f,
)| API | Purpose |
|---|---|
BeforeAfterSlider |
Main composable |
SliderState |
Hoisted progress (0f–1f) |
rememberCompareSliderState() |
Create slider state |
CompareZoomState |
Shared scale and pan for both images |
rememberCompareZoomState() |
Create zoom state |
CompareAnimationMode |
Auto-scrub modes |
CompareImageSource |
Coil / Painter images |
CompareKitDefaults |
Default styling and a11y values |
Package: com.usmandev.comparekit.beforeafterslider
git clone https://github.com/usmandev0/comparekit.git
cd comparekit
./gradlew :androidApp:installDebugThe demo covers basic usage, Coil loading, customization, labels, gestures, orientation, live controls, auto animation, accessibility, and synced zoom/pan.
| Planned | Status |
|---|---|
| Pinch-zoom and pan | Done |
| Magnifier, video comparison | Planned |
| Desktop & Web targets | Planned |
| Accessibility improvements | Done |
See CHANGELOG.md for release history.
./gradlew :CompareKit:compileAndroidMain
./gradlew :CompareKit:compileKotlinIosSimulatorArm64Apache License 2.0 — see LICENSE.
Author: Usman (@usmandev0)
If CompareKit helps your project, consider starring the repo on GitHub.