About
Vary is a lightweight, intuitive responsive layout library for Compose
It helps you effortlessly adapt your UI to different screen sizes like phones, tablets, and desktops using a clean, Kotlin-native DSL. Whether it’s switching entire UI layouts or just tweaking a single values, Vary provides a simple and performant way to build fully responsive interfaces.
Install
Add the dependency to thedependencies block of your build.gradle.kts file in your commonMain source set.
- catalogs
- gradle
1
Step 1
Add the version in your
/gradle/libs.versions.toml file under versionslibs.versions.toml
2
Step 2
Add the library in your
/gradle/libs.versions.toml file under librarieslibs.versions.toml
3
Step 3
Add the library to the
dependencies block of your build.gradle.kts file in your commonMain source set.build.gradle.kts
4
Step 4
Sync project to continue
Setup
To enable screen size detection, you only need to wrap your root composable with theVary provider. This should be done once at the top level of your application.
App.kt
Make it yours
Make it yours
Under the hood
Vary calls LocalWindowInfo.current.containerSize.width to get the width, but you can provide your own implementationvary.kt
Usage
The library provides two main functions all namesvary for switching UI layouts and for selecting values.
Values
Use this to select any non-composable value like a Dp, Color, Int, Modifier, etc. The default (xs) value is a mandatory first parameter.The lambda is not mandatory and it will default to
xs incase no other size is declared Layouts
Use this when you need to render completely different composables for different screen sizes. The default (xs) case is provided as a mandatory trailing lambda.Sizes
Vary provides the following sizes
| Name | Label | Breakpoint |
|---|---|---|
| ExtraSmall | xs | 0 |
| Small | sm | 640 |
| Medium | md | 768 |
| Large | lg | 1024 |
| ExtraLarge | xl | 1280 |
| ExtraExtraLarge | xxl | 1536 |
More
Vary is an open source library and we’re always looking for ways to improve it, you can view more by clicking the link below.
Vary
Build responsive apps with compose