Skip to content

Commit e4396f6

Browse files
authored
Fix missing snippet (#612)
* Fix missing snippet * Apply Spotless --------- Co-authored-by: mlykotom <[email protected]>
1 parent fb85817 commit e4396f6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/interop/InteroperabilityAPIsSnippets.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import androidx.activity.ComponentActivity
3232
import androidx.activity.compose.setContent
3333
import androidx.compose.foundation.layout.Column
3434
import androidx.compose.foundation.layout.fillMaxSize
35+
import androidx.compose.foundation.lazy.LazyColumn
3536
import androidx.compose.material3.Button
3637
import androidx.compose.material3.MaterialTheme
3738
import 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
196219
fun CustomView() {
@@ -231,6 +254,8 @@ fun ContentExample() {
231254
// [START_EXCLUDE silent]
232255
class 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]

0 commit comments

Comments
 (0)