compose-utils

Utility library simplifies development by offering platform-specific tools and shared abstractions for managing coroutine dispatchers, accessing platform details, handling preferences, and launching URLs across Compose environments.

Android
JVM
iOS
macOS
Wasm
JS
GitHub stars0
Dependents0
Creation datealmost 2 years ago

Last activity9 months ago
Latest release3.1.2 (9 months ago)

Compose Utils


ComposeUtils is a utility library designed to streamline development in Compose Multiplatform projects. This package provides a set of platform-specific utilities and shared abstractions tailored for use in Compose environments across Android, iOS, and other platforms supported by Kotlin Multiplatform. With tools for managing coroutine dispatchers, accessing platform information, handling preferences, and launching URLs, ComposeUtils simplifies cross-platform development by offering consistent, easy-to-use interfaces and functions that work seamlessly in Compose-based projects.

📦 Utility Libraries


🌐 Networking

  • Network Connectivity
    ➜ Network Connectivity

  • Ktor Error Handling
    ⚠️ Deprecated
    ➜ Compose Ktor Error Handler

    This library is no longer maintained or updated.
    You are free to copy and reuse its source code as needed.
    Feel free to adapt the logic to match your API error response structure and validation format.

open url

openUrl("https://maps.app.goo.gl/qnPYcxLP9Y9Y74od8")

Prefs

functionality

expect class SharedPrefs() {
    fun putInt(key: String, value: Int)
    fun putString(key: String, value: String)
    fun putBool(key: String, value: Boolean)
    fun getInt(key: String, default: Int?): Int
    fun getString(key: String): String?
    fun getBool(key: String, default: Boolean?): Boolean
    fun remove(key: String)

}

How use it

    val prefs = SharedPrefs()
...
ElevatedButton(onClick = {
    prefs.putInt() // or any function need
})

Platform details

Functionality

expect class PlatformData() {
    val name: String
    val deviceName: String
    val version: String
    val model: String
    val manufacturer: String
}

How to use it

    val platformData = PlatformData()
...
ElevatedButton(onClick = {
    println(platformData.name)
})
  • Note support Either<out L, out R>

V 1.1.0

  • Support Ktor error handler

First need run this one time

KtorErrorHandler().init()

Second after catch error

internal class GetLecturesFilterRepository(
    private val remoteDataSource: RemoteDataSource
) {
    suspend fun invoke(lecturesFilterRequest: LecturesFilterRequest): Either<Failure, LecturesFilterModel> {
        return try {
            val result = remoteDataSource.getLecturesFilter(lecturesFilterRequest)
            val data = result.toModel()
            Either.Right(data)
        } catch (e: Exception) {
            Either.Left(KtorErrorHandler().handle(e))
        }
    }
}

Third need get error from data example

    val result = loginUseCase.invoke(loginRequest)

     result.fold(
        right = {
            data = it
        },
        left = {
            state.value = state.value.copy(errorMessage = (it as Map)["errorMessage"],
            errorForm = (it as Map)["invalid fields"])
        }
    )
Android
JVM
iOS
macOS
Wasm
JS
GitHub stars0
Dependents0
Creation datealmost 2 years ago

Last activity9 months ago
Latest release3.1.2 (9 months ago)

Compose Utils


ComposeUtils is a utility library designed to streamline development in Compose Multiplatform projects. This package provides a set of platform-specific utilities and shared abstractions tailored for use in Compose environments across Android, iOS, and other platforms supported by Kotlin Multiplatform. With tools for managing coroutine dispatchers, accessing platform information, handling preferences, and launching URLs, ComposeUtils simplifies cross-platform development by offering consistent, easy-to-use interfaces and functions that work seamlessly in Compose-based projects.

📦 Utility Libraries


🌐 Networking

  • Network Connectivity
    ➜ Network Connectivity

  • Ktor Error Handling
    ⚠️ Deprecated
    ➜ Compose Ktor Error Handler

    This library is no longer maintained or updated.
    You are free to copy and reuse its source code as needed.
    Feel free to adapt the logic to match your API error response structure and validation format.

open url

openUrl("https://maps.app.goo.gl/qnPYcxLP9Y9Y74od8")

Prefs

functionality

expect class SharedPrefs() {
    fun putInt(key: String, value: Int)
    fun putString(key: String, value: String)
    fun putBool(key: String, value: Boolean)
    fun getInt(key: String, default: Int?): Int
    fun getString(key: String): String?
    fun getBool(key: String, default: Boolean?): Boolean
    fun remove(key: String)

}

How use it

    val prefs = SharedPrefs()
...
ElevatedButton(onClick = {
    prefs.putInt() // or any function need
})

Platform details

Functionality

expect class PlatformData() {
    val name: String
    val deviceName: String
    val version: String
    val model: String
    val manufacturer: String
}

How to use it

    val platformData = PlatformData()
...
ElevatedButton(onClick = {
    println(platformData.name)
})
  • Note support Either<out L, out R>

V 1.1.0

  • Support Ktor error handler

First need run this one time

KtorErrorHandler().init()

Second after catch error

internal class GetLecturesFilterRepository(
    private val remoteDataSource: RemoteDataSource
) {
    suspend fun invoke(lecturesFilterRequest: LecturesFilterRequest): Either<Failure, LecturesFilterModel> {
        return try {
            val result = remoteDataSource.getLecturesFilter(lecturesFilterRequest)
            val data = result.toModel()
            Either.Right(data)
        } catch (e: Exception) {
            Either.Left(KtorErrorHandler().handle(e))
        }
    }
}

Third need get error from data example

    val result = loginUseCase.invoke(loginRequest)

     result.fold(
        right = {
            data = it
        },
        left = {
            state.value = state.value.copy(errorMessage = (it as Map)["errorMessage"],
            errorForm = (it as Map)["invalid fields"])
        }
    )