Skip to content

Latest commit

 

History

History
113 lines (84 loc) · 3.44 KB

README.md

File metadata and controls

113 lines (84 loc) · 3.44 KB

Buff

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

⚠️Non mainstream warning:If the content on this page causes your discomfort,please press Ctrl+W

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 "1.8.20-1.0.10"//this,The left 1.8.20 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 1.0.1
    ksp("io.github.ltttttttttttt:Buff:$version")//this,such as 1.0.1
}
  • If it is multi-platform, add it to build.gradle.kts in the common module directory
plugins {
    ...
    id("com.google.devtools.ksp") version "1.8.20-1.0.10"
}

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

...
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) not in the constructor will be automatically converted to MutableState<T>

@Buff
class BuffBean(
    val id: Int? = null,
) {
    var name: String? = null
}

Example(reference UseBuff.kt):

val buffBean = BuffBean(0)
val bean = buffBean.addBuff()//Transform to the BuffBeanWithBuff
bean.name//The name'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

Serialize of this project uses kotlinx-serialization by default, If using other serialization support, modify it, Your app dir, build.gradle.kts add:

ksp {
    //Set the Annotation of the class, Usually as follows
    arg("classSerializeAnnotationWithBuff", "//Not have")
    //Set the Annotation of the field to transient, Usually as follows
    arg("fieldSerializeTransientAnnotationWithBuff", "@kotlin.jvm.Transient")
}

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