Skip to content

Instantly share code, notes, and snippets.

@burnoo
Created April 4, 2022 16:31
Show Gist options
  • Save burnoo/29be79794da6de7bfb76f6df2ea158f3 to your computer and use it in GitHub Desktop.
Save burnoo/29be79794da6de7bfb76f6df2ea158f3 to your computer and use it in GitHub Desktop.
Two-way data binding in Jetpack Compose 3
class MutableStateAdapter<T>(
private val state: State<T>,
private val mutate: (T) -> Unit
) : MutableState<T> {
override var value: T
get() = state.value
set(value) {
mutate(value)
}
override fun component1(): T = value
override fun component2(): (T) -> Unit = { value = it }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment