Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arriolac/2445fc05e655a8bea1dc64b61da44d2d to your computer and use it in GitHub Desktop.
Save arriolac/2445fc05e655a8bea1dc64b61da44d2d to your computer and use it in GitHub Desktop.
Example of using Compose in RecyclerView before pooling container was introduced.
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import androidx.compose.ui.platform.ViewCompositionStrategy
class MyComposeViewHolder(
val composeView: ComposeView
) : RecyclerView.ViewHolder(composeView) {
init {
// This is from the previous guidance
// NOTE: **Do not** do this with Compose 1.2.0-beta02+
// and RecyclerView 1.3.0-alpha02+
composeView.setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
}
fun bind(input: String) {
composeView.setContent {
MdcTheme {
Text(input)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment