https://kotlinlang.org logo
Title
u

ursus

11/27/2021, 5:03 AM
Could one say Compose ui is more equivalent to flutter ui, than os native?
:yes: 1
k

K Merle

11/27/2021, 5:15 AM
Yes. Both of them have declarative way of writing UI, unlike old View system that is imperative.
a

Albert Chang

11/27/2021, 8:40 AM
In terms of code style it may be true but in terms of internals, not really. Flutter does many things (e.g. all the rendering) itself while Jetpack Compose usually uses platform native mechanism.
y

yschimke

11/27/2021, 11:07 AM
My understanding was that Compose actually reimplements the native controls and draws to a canvas.
a

agrosner

11/27/2021, 1:21 PM
Compose is similar to flutter. It doesn't use native mechanics in terms of the view- flutter same thing. If you meant like React Native which reuses android view widgets
Compose and flutter both draw straight to canvas
a

Albert Chang

11/27/2021, 2:40 PM
Not really. Jetpack Compose doesn’t directly draw to canvas. It uses RenderNode API on API 23-27 and API 29+, and View API on API 21-22 and API 28. Rendering is all done by the platform, same as View system. See the source here for details.
u

ursus

11/27/2021, 2:47 PM
Yea one big ComposeView but your actual ui elements are "just" canvas calls, no?
s

Stylianos Gakis

11/27/2021, 2:48 PM
What happened with API 28 in particular? Seems really odd that older versions use RenderNode that the latest use too, but all of a sudden API 28 also uses what’s being used by the quite old API 21-22 versions?
a

Albert Chang

11/27/2021, 2:50 PM
Another obvious proof is that Jetpack Compose doesn’t bundle any rendering libraries, while flutter bundles Skia for rendering.
Before API 29
RenderNode
is system hidden API and on API 28 it is in the blocklist of non-sdk API usage.
1
u

ursus

11/27/2021, 2:54 PM
So is my assumption wrong? Thats its one big View instance from OS point of view?
a

Albert Chang

11/27/2021, 2:54 PM
It’s true on API 23-27 and API 29+.
u

ursus

11/27/2021, 2:58 PM
And flutter doesnt do the same thing? i.e. on big FlutterView where its draws by opengl or whatever they do
a

Albert Chang

11/27/2021, 3:10 PM
Jetpack Compose: Create a custom view, override its
onDraw()
and use standard Android
Canvas
API to do some drawing, letting the platform handle all the rendering stuff. Flutter: Create a
SurfaceView
, do custom drawing using its own API and rendering to the
Surface
using Skia. Am I clear?
u

ursus

11/27/2021, 3:23 PM
yea btw isnt canvas implemented in skia?
a

Albert Chang

11/27/2021, 3:44 PM
The rendering part of Android is called HWUI. If you are interested you can do some searching using that keyword but tl;dr: not necessarily.
a

Adam Powell

11/27/2021, 3:51 PM
@Albert Chang has the right of it. If you're looking for a quick analogy, Compose UI is closer to being a RecyclerView2 than it is to Flutter in terms of how they interact with Android
r

romainguy

11/27/2021, 6:14 PM
And to be clear: the platform’s Canvas uses Skia internally
hwui is a layer on top that did all the drawing for many years but since P, Skia does the drawing again. hwui does a lot of other things though (managing render nodes, animations, frame pacing, etc.)
(And before Android 3.0, Canvas was pure, direct Skia)
a

agrosner

11/27/2021, 6:19 PM
So…Skia everywhere 😅
r

romainguy

11/27/2021, 6:20 PM
More or less yes. Skia came from Android so it makes sense we and other google teams use it
👍 2
Chrome uses Skia too