Created
June 27, 2022 20:48
-
-
Save arriolac/7961d78646e951994f3cba1fb445dcea 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.ComposeView | |
class MyComposeAdapter : RecyclerView.Adapter<MyComposeViewHolder>() { | |
override fun onCreateViewHolder( | |
parent: ViewGroup, | |
viewType: Int, | |
): MyComposeViewHolder { | |
return MyComposeViewHolder(ComposeView(parent.context)) | |
} | |
override fun onViewRecycled(holder: MyComposeViewHolder) { | |
// This is from the previous guidance | |
// NOTE: You **do not** want to do this with Compose 1.2.0-beta02+ | |
// and RecyclerView 1.3.0-alpha02+ | |
holder.composeView.disposeComposition() | |
} | |
/* Other methods */ | |
} | |
class MyComposeViewHolder( | |
val composeView: ComposeView | |
) : RecyclerView.ViewHolder(composeView) { | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment