A powerful and customizable utility library for Jetpack Compose, designed to provide helpful extensions for common Jetpack Compose classes.
Compose Utils is a feature-rich library that provides helper and extension functions to simplify
common tasks. It offers serializable and parcelable data classes for core Jetpack Compose data types
like Offset, Size, IntOffset, IntSize, DpOffset, and DpSize, making state management and
data transfer more robust.
- Serializable & Parcelable Data Classes: Easily handle, save, and restore UI-related data
across configuration changes or process death.
OffsetDataSizeDataIntOffsetDataIntSizeDataDpOffsetDataDpSizeData
- Seamless Conversion: Effortlessly convert between Jetpack Compose's core classes and their
compose-utilsdata counterparts. - State Management: Simplify the process of saving and restoring UI state in your Jetpack Compose applications.
- Easy Integration: Built to be lightweight and easy to integrate into any Jetpack Compose project.
Groovy (build.gradle):
dependencies {
implementation 'com.github.bashpsk.emptylibs:compose-utils:<latest-version>'
}Kotlin DSL (build.gradle):
dependencies {
implementation("com.github.bashpsk.emptylibs:compose-utils:<latest-version>")
}Kotlin DSL with Version Catalogs:
[versions]
empty-libs = "<latest-version>"
[libraries]
emptylibs-compose-utils = { group = "com.github.bashpsk.emptylibs", name = "compose-utils", version.ref = "empty-libs" }dependencies {
implementation(libs.emptylibs.compose.utils)
}Integrating compose-utils into your app is straightforward. The library provides extension
functions to convert between Compose objects and their corresponding data objects.
Here is a complete example demonstrating how to convert an Offset to OffsetData and back:
// Create an Offset
val originalOffset = Offset(100f, 200f)
// Convert Offset to OffsetData for serialization or state saving
val offsetData by rememberSaveable { mutableStateOf(originalOffset.toOffsetData()) }
// ... (pass offsetData through bundles or save it)
// Convert back to an Offset to use in your Composables
val restoredOffset = offsetData.toOffset()The library is organized by the data types it supports. Here are the main extension functions you will use:
Offset.toOffsetData(): OffsetDataOffsetData.toOffset(): OffsetDpOffset.toDpOffsetData(): DpOffsetDataDpOffsetData.toDpOffset(): DpOffsetIntOffset.toIntOffsetData(): IntOffsetDataIntOffsetData.toIntOffset(): IntOffset
Size.toSizeData(): SizeDataSizeData.toSize(): SizeDpSize.toDpSizeData(): DpSizeDataDpSizeData.toDpSize(): DpSizeIntSize.toIntSizeData(): IntSizeDataIntSizeData.toIntSize(): IntSize