https://kotlinlang.org logo
#compose
Title
# compose
t

Tin Tran

11/09/2023, 4:51 PM
I’m having a
SurfaceView
like this. It’s seems like
Modifier.alpha
do not have any affect. The view is a video frame rendered by
MediaCodec
so every time the surface is destroyed I release the
MediaCode
so I don’t want it to be destroyed and recreated unless i’m done with it. How can I hide it on condition?
Copy code
AndroidView(
    factory = {
        view.holder.addCallback(surfaceCallback)
        view
    },
    modifier = Modifier
        .alpha(if (condition) 1f else 0f)
        .matchParentSize(),
)
s

shikasd

11/09/2023, 8:31 PM
SurfaceView
is weird one because it does not really draw on regular canvas, that's why alpha has no effect. I wonder if setting
SurfaceView
to
View.INVISIBLE
will have any effect here?
c

Chris Fillmore

11/09/2023, 10:19 PM
Maybe track your SurfaceView separately, manage its lifecycle on your own, and conditionally show the AndroidView
t

Tin Tran

11/10/2023, 2:56 AM
Setting to
View.INVISIBLE
resulted in the underlying surface recreated which I don’t want….
Changing to
TextureView
solved my problem. Thanks guys
2 Views