File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
compose/snippets/src/main/java/com/example/compose/snippets/interop Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -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
@@ -191,6 +192,28 @@ class ExampleFragmentMultipleComposeView : Fragment() {
191192}
192193// [END android_compose_interop_apis_compose_in_fragment_multiple]
193194
195+ // [START android_compose_interop_apis_android_view_reuse]
196+ @Composable
197+ fun AndroidViewInLazyList () {
198+ LazyColumn {
199+ items(100 ) { index ->
200+ AndroidView (
201+ modifier = Modifier .fillMaxSize(), // Occupy the max size in the Compose UI tree
202+ factory = { context ->
203+ MyView (context)
204+ },
205+ update = { view ->
206+ view.selectedItem = index
207+ },
208+ onReset = { view ->
209+ view.clear()
210+ }
211+ )
212+ }
213+ }
214+ }
215+ // [END android_compose_interop_apis_android_view_reuse]
216+
194217// [START android_compose_interop_apis_views_in_compose]
195218@Composable
196219fun CustomView () {
@@ -231,6 +254,8 @@ fun ContentExample() {
231254// [START_EXCLUDE silent]
232255class MyView (context : Context ) : View(context) {
233256 var selectedItem: Int = 0
257+
258+ fun clear () { }
234259}
235260// [END_EXCLUDE silent]
236261// [END android_compose_interop_apis_views_in_compose]
You can’t perform that action at this time.
0 commit comments