Sergey Y.
05/06/2024, 8:50 PMAndroidExternalSurface
on Android versions lower than API 31. When I add an AndroidExternalSurface
with a fixed surface size to my layout and draw a small green rectangle on it, everything looks as expected on API 31 and above. I can see my regular composable content, its background, and the green rectangle.
However, on APIs 30 and lower, the behavior is different. I only see my composable content that's on top of the AndroidExternalSurface
and the colored rectangle I drew on the surface. The remaining layout background is not visible, and the rest of the screen area is filled with black.
Is this the expected behavior for AndroidExternalSurface
on older APIs? Changing the Modifier.size
or the surfaceSize
attribute doesn't seem to affect the appearance on API 30 and below.
Any insights or suggestions would be greatly appreciated. Thanks in advance! 🙂Sergey Y.
05/06/2024, 8:51 PMBox(
modifier = Modifier
.fillMaxSize()
.background(Color.Cyan)
.safeDrawingPadding()
) {
val intSize = with(LocalDensity.current) { DpSize(100.dp, 100.dp).toSize().toIntSize() }
AndroidExternalSurface(
Modifier
.requiredSize(100.dp)
.offset(100.dp),
surfaceSize = intSize,
isOpaque = false
) {
onSurface { surface, width, height ->
surface.lockCanvas(Rect(0, 0, width, height)).apply {
drawColor(Color.Green.toArgb())
surface.unlockCanvasAndPost(this)
}
}
}
Text(
text = "Hello Android!",
color = Color.Red
)
}
romainguy
05/06/2024, 8:53 PMSergey Y.
05/06/2024, 8:53 PMromainguy
05/06/2024, 8:53 PMSergey Y.
05/06/2024, 8:54 PMSergey Y.
05/06/2024, 8:54 PMSergey Y.
05/06/2024, 8:55 PMSergey Y.
05/06/2024, 8:56 PMSergey Y.
05/06/2024, 9:05 PMAndroidEmbeddedExternalSurface
seems to work as I expect, and I know it utilizes a TextureView
under the hood. This should be fine for my use case.Sergey Y.
05/06/2024, 9:52 PMSergey Y.
05/06/2024, 9:54 PMSergey Y.
05/06/2024, 9:54 PMTextureView
seems to be working fine. Thank you so much for your attention 🙂Sergey Y.
05/19/2024, 10:16 PMSurfaceView
inside a FrameLayout
makes it work properly.romainguy
05/19/2024, 10:33 PMSergey Y.
05/19/2024, 11:01 PMSergey Y.
05/19/2024, 11:01 PMromainguy
05/19/2024, 11:19 PMSergey Y.
05/19/2024, 11:47 PMSergey Y.
05/19/2024, 11:49 PMSergey Y.
05/20/2024, 12:01 AMSergey Y.
05/20/2024, 12:03 AM.clipToBounds
or .align
Sergey Y.
05/20/2024, 12:15 AM