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
32
32
import androidx.activity.compose.setContent
33
33
import androidx.compose.foundation.layout.Column
34
34
import androidx.compose.foundation.layout.fillMaxSize
35
+ import androidx.compose.foundation.lazy.LazyColumn
35
36
import androidx.compose.material3.Button
36
37
import androidx.compose.material3.MaterialTheme
37
38
import androidx.compose.material3.Text
@@ -191,6 +192,28 @@ class ExampleFragmentMultipleComposeView : Fragment() {
191
192
}
192
193
// [END android_compose_interop_apis_compose_in_fragment_multiple]
193
194
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
+
194
217
// [START android_compose_interop_apis_views_in_compose]
195
218
@Composable
196
219
fun CustomView () {
@@ -231,6 +254,8 @@ fun ContentExample() {
231
254
// [START_EXCLUDE silent]
232
255
class MyView (context : Context ) : View(context) {
233
256
var selectedItem: Int = 0
257
+
258
+ fun clear () { }
234
259
}
235
260
// [END_EXCLUDE silent]
236
261
// [END android_compose_interop_apis_views_in_compose]
You can’t perform that action at this time.
0 commit comments