Last active
July 14, 2022 18:32
-
-
Save arriolac/2445fc05e655a8bea1dc64b61da44d2d to your computer and use it in GitHub Desktop.
Example of using Compose in RecyclerView before pooling container was introduced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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