@@ -32,6 +32,7 @@ import androidx.activity.ComponentActivity
3232import androidx.activity.compose.setContent
3333import androidx.compose.foundation.layout.Column
3434import androidx.compose.foundation.layout.fillMaxSize
35+ import androidx.compose.foundation.lazy.LazyColumn
3536import androidx.compose.material3.Button
3637import androidx.compose.material3.MaterialTheme
3738import androidx.compose.material3.Text
@@ -42,6 +43,7 @@ import androidx.compose.runtime.mutableIntStateOf
4243import androidx.compose.runtime.remember
4344import androidx.compose.runtime.rememberUpdatedState
4445import androidx.compose.runtime.setValue
46+ import androidx.compose.ui.ExperimentalComposeUiApi
4547import androidx.compose.ui.Modifier
4648import androidx.compose.ui.platform.ComposeView
4749import androidx.compose.ui.platform.LocalContext
@@ -191,6 +193,28 @@ class ExampleFragmentMultipleComposeView : Fragment() {
191193}
192194// [END android_compose_interop_apis_compose_in_fragment_multiple]
193195
196+ // [START android_compose_interop_apis_android_view_reuse]
197+ @Composable
198+ fun AndroidViewInLazyList () {
199+ LazyColumn {
200+ items(100 ) { index ->
201+ AndroidView (
202+ modifier = Modifier .fillMaxSize(), // Occupy the max size in the Compose UI tree
203+ factory = { context ->
204+ MyView (context)
205+ },
206+ update = { view ->
207+ view.selectedItem = index
208+ },
209+ onReset = { view ->
210+ view.clear()
211+ }
212+ )
213+ }
214+ }
215+ }
216+ // [END android_compose_interop_apis_android_view_reuse]
217+
194218// [START android_compose_interop_apis_views_in_compose]
195219@Composable
196220fun CustomView () {
@@ -231,6 +255,8 @@ fun ContentExample() {
231255// [START_EXCLUDE silent]
232256class MyView (context : Context ) : View(context) {
233257 var selectedItem: Int = 0
258+
259+ fun clear () { }
234260}
235261// [END_EXCLUDE silent]
236262// [END android_compose_interop_apis_views_in_compose]
0 commit comments