```CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { AndroidView( ...
s
Copy code
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
    AndroidView(
        factory = { context ->
            PreviewView(context).apply {
                this.layoutParams = ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
                preview.setSurfaceProvider(this.surfaceProvider)
            }
        },
        modifier = Modifier.fillMaxSize()
    )
}
I wrapped a camera preview within CompositionLocalProvider and gave an alpha value to medium, it does not work. anyone have some idea ?
a
PreviewView is not a consumer of LocalContentAlpha, as it has no dependency on the compose-material library to know that it exists. What result are you looking for?
s
I wanted to have a text show on top of the camera preview view. and lower the opacity of camera preview view.
Copy code
Box(modifier = Modifier.fillMaxSize()) {
    CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
        AndroidView(
            factory = { context ->
                PreviewView(context).apply {
                    this.layoutParams = ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                    preview.setSurfaceProvider(this.surfaceProvider)
                }
            },
            modifier = Modifier.fillMaxSize()
        )
    }
    CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
        Text(
            text = "Code",
            fontSize = 30.sp
        )
    }
}
a
you might instead draw a translucent black over it to "dim" it
the most efficient way for something like a camera preview to operate on android is to use a SurfaceView internally, which plays by some relatively strange rules when it interacts with the rest of the UI around it
in essence, SurfaceView cuts a "hole" in your UI, and places the actual surface being managed beneath your window, so it's not subject to a lot of the kinds of rendering effects you might try to place on it
but you can draw over it, so a translucent color drawn on top will work.
👍 1
s
it works with translucent black. (Y)
👍 1
👍🏼 1