Kyant0/Capsule

Jetpack Compose smooth corners

Kotlin

195

2 commits

updated Jan 27, 2026

See the code

README

Capsule

Capsule is a Jetpack Compose library that creates G2 continuous rounded rectangles.

Different types of rounded rectangles

Customizable curvature combs:

Different curvature combs

Playground app

Screenshot of the playground app

Installation

Maven Central

In build.gradle.kts, add

implementation("io.github.kyant0:capsule:<version>")

Usages

Replace the RoundedCornerShape with ContinuousRoundedRectangle or ContinuousCapsule:

// create a basic rounded corner shape
ContinuousRoundedRectangle(16.dp)

// create a capsule shape
ContinuousCapsule

Custom continuity:

val g1 = G1Continuity // no corner smoothness
val g2 = G2Continuity(
    profile = G2ContinuityProfile.RoundedRectangle.copy(
        extendedFraction = 0.5,
        arcFraction = 0.5,
        bezierCurvatureScale = 1.1,
        arcCurvatureScale = 1.1
    ),
    capsuleProfile = G2ContinuityProfile.Capsule.copy(
        extendedFraction = 0.5,
        arcFraction = 0.25
    )
)

// create shapes with custom continuity
ContinuousRoundedRectangle(16.dp, continuity = g2)
ContinuousCapsule(continuity = g2)

The following parameters are supported by G2ContinuityProfile:

  • extended fraction: the transition length between original corner and line, relative to the corner radius
  • arc fraction: the ratio of the arc to the corner
  • Bezier curvature scale: the multiplier of the end curvature of the Bezier curve
  • arc curvature scale: the multiplier of the arc curvature

Note: It guarantees G1 continuity at least. Only if the Bezier curvature scale equals the arc curvature scale, it will have exact G2 continuity.

Tips

Performance

Drawing cubic Bézier curves on Android performs poorly. However, the Capsule library uses a very efficient method to calculate the control points, achieving optimal theoretical performance.

When the shape area is large (almost fullscreen) and the corner radius is constantly changing, performance may decrease. Use animatedShape.copy(continuity = G1Continuity) to temporarily disable corner smoothing during the animation.

jetpack-compose

Kyant0/Capsule

Jetpack Compose smooth corners

Kotlin

195

2 commits

updated Jan 27, 2026

See the code

README

Capsule

Capsule is a Jetpack Compose library that creates G2 continuous rounded rectangles.

Different types of rounded rectangles

Customizable curvature combs:

Different curvature combs

Playground app

Screenshot of the playground app

Installation

Maven Central

In build.gradle.kts, add

implementation("io.github.kyant0:capsule:<version>")

Usages

Replace the RoundedCornerShape with ContinuousRoundedRectangle or ContinuousCapsule:

// create a basic rounded corner shape
ContinuousRoundedRectangle(16.dp)

// create a capsule shape
ContinuousCapsule

Custom continuity:

val g1 = G1Continuity // no corner smoothness
val g2 = G2Continuity(
    profile = G2ContinuityProfile.RoundedRectangle.copy(
        extendedFraction = 0.5,
        arcFraction = 0.5,
        bezierCurvatureScale = 1.1,
        arcCurvatureScale = 1.1
    ),
    capsuleProfile = G2ContinuityProfile.Capsule.copy(
        extendedFraction = 0.5,
        arcFraction = 0.25
    )
)

// create shapes with custom continuity
ContinuousRoundedRectangle(16.dp, continuity = g2)
ContinuousCapsule(continuity = g2)

The following parameters are supported by G2ContinuityProfile:

  • extended fraction: the transition length between original corner and line, relative to the corner radius
  • arc fraction: the ratio of the arc to the corner
  • Bezier curvature scale: the multiplier of the end curvature of the Bezier curve
  • arc curvature scale: the multiplier of the arc curvature

Note: It guarantees G1 continuity at least. Only if the Bezier curvature scale equals the arc curvature scale, it will have exact G2 continuity.

Tips

Performance

Drawing cubic Bézier curves on Android performs poorly. However, the Capsule library uses a very efficient method to calculate the control points, achieving optimal theoretical performance.

When the shape area is large (almost fullscreen) and the corner radius is constantly changing, performance may decrease. Use animatedShape.copy(continuity = G1Continuity) to temporarily disable corner smoothing during the animation.

jetpack-compose

Project health

Latest release

2.1.3 · Jan 26, 2026

Releases this year

3

Significant stargazers

Nishant Srivastava

2,546 followers · starred Aug 2025

Andrey Mischenko

245 followers · starred Aug 2025

Amirreza Gholami

72 followers · starred Nov 2025