takahirom / groupie-compose-item

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

groupie-compose-item

You can treat Compose as a regular Groupie item!

This library is very simple and small. You can check the source code based on Integrating Compose with your existing UI.

class TextComposeItem(val text: String) :
  ComposeItem<TextComposeItem2.Binding>(text.hashCode().toLong()) {
  class Binding : ComposeBinding {
    var text by mutableStateOf("")

    @Composable
    override fun Content() {
      val firstText = remember { text }
      LaunchedEffect(key1 = text) {
        println("createTimeText:$firstText current:$text")
      }
      DisposableEffect(key1 = Unit) {
        onDispose {
          println("dispose:$text")
        }
      }
      Item(text)
    }
  }
  
  override fun composeBindingClass(): KClass<Binding> {
    return Binding::class
  }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
  ComposeingroupieTheme {
    val textComposeItem = TextComposeItem(text = "Hello!!!!!")
    val composeBinding = textComposeItem.composeBinding()
    textComposeItem.bind(composeBinding, 0)
    composeBinding.Content()
  }
}

How to use

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
  implementation 'com.github.takahirom.groupie-compose-item:composeitem:0.1.0'
}

About

License:Apache License 2.0


Languages

Language:Kotlin 100.0%