https://kotlinlang.org logo
#compose-android
Title
# compose-android
s

Suhaib Roomy

12/01/2023, 10:31 AM
Hey people! I was looking into Rive and found that they don't have a compose version of the library. I looked into if I can contribute into this project to add support for composable but I found that Compose doesn't have a TextureView or a SurfaceView. In the new 1.6 version, compose now has AndroidExternalSurface which got me excited but when I looked into the implementation, its just a wrapper around the good old SurfaceView. I don't know a lot about SurfaceView so I wanted to know if anyone has an idea why the compose team went ahead with a wrapper which might introduce performance overhead because of the bridging.
t

Thomas Hormes

12/01/2023, 11:29 AM
It seems to be on their Roadmap, though there is not a whole lot of information on the progress, or whether they have started working on compose support at all. See this issue for more info: https://github.com/rive-app/rive-android/issues/259
s

Sergey Y.

12/01/2023, 12:38 PM
You might think of Jetpack Compose as a fancy custom android View, that draw content using standard canvas APIs. SurfaceView in Android is a specialized view that offers direct access to a dedicated hardware buffer, allowing for efficient drawing and manipulation of graphics. It operates at a lower level than standard views like View, providing greater control over drawing and rendering processes. Replicating SurfaceView in Compose would require a complete overhaul using OpenGL or Vulkan, bypassing the Canvas API used in Compose's drawing system.
That's why SurfaceView/WebView/TextureView will always be basic AndroidView wrappers in Compose. And it is completely fine.
r

romainguy

12/01/2023, 4:33 PM
SurfaceView
and
TextureView
are both quite unique and can’t be replicated outside of the OS
Well, you can mostly with never APIs, but this couldn’t be backported
Also the “overhead” of the composables wrappers is close to irrelevant for those particular views
@Sergey Y.
SurfaceView
has nothing to do with OpenGL/Vulkan/Canvas
s

Sergey Y.

12/01/2023, 8:30 PM
What I mean is that the only way to create a “Compose SurfaceView” is to have ComposeView inherit from SurfaceView and implement the compose renderer using some graphics API that uses the surface provided by SurfaceView. I hope you understand what I mean.
r

romainguy

12/01/2023, 8:34 PM
But that's not what we're discussing here
And Compose could render in a SurfaceView today just fine
s

Sergey Y.

12/01/2023, 9:17 PM
Than I lost the thread 😞 By rendering in a SurfaceView do you mean something like https://developer.android.com/reference/android/view/SurfaceHolder#lockCanvas() and replace original Compose's Canvas by this?
5 Views