Regarding the reuse of an Android View. Is there a...
# compose
a
Regarding the reuse of an Android View. Is there any way of unloading resources once the view is destroyed? I want to avoid leaking things.
Concretely I have the usecase of rendering to a TextureView with ExoPlayer
Copy code
@Composable
fun VideoRenderView(
    modifier: Modifier = Modifier,
    videoRenderViewModel: VideoRenderViewModel,
    update: TextureView.(SimpleExoPlayer) -> Unit,
) {
    AndroidView(
        factory = { context ->
            val textureView = TextureView(context)
            val player = videoRenderViewModel.player

            player.setVideoTextureView(textureView)

            textureView.tag = player
            textureView
        },
        modifier = modifier,
        update = {
            update(it, it.tag as SimpleExoPlayer)
        }
    )
}
Within the factory I set the textureView as output to the player. Since the player has a different lifecycle I probably have to unset the textureView (e.g.
player.setVideoTextureView(null)
) somewhere. Is there a place for those things in compose?
h
you might want to try
DisposableEffect
😎 1
a
Thanks @Halil Ozercan this looks like exactly what I need