Skip to content

ltttttttttttt/Buff

Repository files navigation

Buff

Add status to beans in Compose Multiplatform, Fields in beans can be directly used as the MutableState<T>

us English | cn 简体中文

ability

  1. Convert some fields in beans to MutableState<T> that can be used directly

How to use

Step 1 and 2.add dependencies:

version =

  • If it is a single platform, add it to build.gradle.kts in the app module directory
plugins {
    ...
    id("com.google.devtools.ksp") version "2.1.21-2.0.1"//this,The left 2.1.21 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}

dependencies {
    ...
    implementation("io.github.ltttttttttttt:Buff-lib:$version")//this,such as 2.0.2
    ksp("io.github.ltttttttttttt:Buff:$version")//this,such as 2.0.2
}
  • If it is multi-platform, add it to build.gradle.kts in the common module directory
plugins {
    ...
    id("com.google.devtools.ksp") version "2.1.21-2.0.1"
}

...
val commonMain by getting {
    dependencies {
        ...
        api("io.github.ltttttttttttt:Buff-lib:$version")//this,such as 2.0.2
    }
}

...
dependencies {
    add("kspCommonMainMetadata", "io.github.ltttttttttttt:Buff:$version")
}

Step 3.Use Buff

Add the @Buff to your bean, call the addBuff() transform to the new Any, The attribute (such as name) will be automatically converted to MutableState<T>

@Buff
class BuffBean(
    val id: Int? = null,
) {
    var isSelect: Boolean = false
}

Example(reference UseBuff.kt):

val buffBean = BuffBean(0)
val bean = buffBean.addBuff()//Transform to the BuffBeanWithBuff
bean.isSelect = true//The isSelect's getter and setter have the effect of MutableState<T>
bean.removeBuff()//Fallback to BuffBean(optional)

Step 4.If you are using a version of ksp less than 1.0.9, the following configuration is required:

Ksp configuration

Step 5.Optional configuration

@Buff(
    scope,//which attributes of the bean should be buffed
    variability//What mutable properties to deal with
)

Add custom code, reference [KspOptions.handlerCustomCode], Your app dir, build.gradle.kts add:

ksp {
    arg("customInClassWithBuff", "//Class end")//in class
    arg("customInFileWithBuff", "//File end")//in file
}

The project provides support for Compose variability annotations. If the original bean has @Stable or @Immutable annotations, the generated Buff class also has corresponding annotations

About

Add status to beans in Compose, Fields in beans can be directly used as the MutableState<T>

Topics

Resources

License

Stars

9 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages