https://github.com/ltttttttttttt/buff
Add status to beans in Compose, Fields in beans can be directly used as the MutableState<T>
https://github.com/ltttttttttttt/buff
compose jetpack-compose kmm kotlin ksp state
Last synced: 3 months ago
JSON representation
Add status to beans in Compose, Fields in beans can be directly used as the MutableState<T>
- Host: GitHub
- URL: https://github.com/ltttttttttttt/buff
- Owner: ltttttttttttt
- License: apache-2.0
- Created: 2022-10-19T03:41:49.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-03T06:33:35.000Z (3 months ago)
- Last Synced: 2025-07-03T07:34:52.814Z (3 months ago)
- Topics: compose, jetpack-compose, kmm, kotlin, ksp, state
- Language: Kotlin
- Homepage:
- Size: 634 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
= [](https://repo1.maven.org/maven2/io/github/ltttttttttttt/Buff/)* If it is a single platform, add it to build.gradle.kts in the app module directory
```kotlin
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
```kotlin
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>```kotlin
@Buff
class BuffBean(
val id: Int? = null,
) {
var name: String? = null
}
```Example(reference UseBuff.kt):
```kotlin
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
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:
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:```kotlin
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:
```kotlin
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