Could one say Compose ui is more equivalent to flu...
# compose
u
Could one say Compose ui is more equivalent to flutter ui, than os native?
👌 1
k
Yes. Both of them have declarative way of writing UI, unlike old View system that is imperative.
a
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
My understanding was that Compose actually reimplements the native controls and draws to a canvas.
a
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
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
Yea one big ComposeView but your actual ui elements are "just" canvas calls, no?
s
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
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
So is my assumption wrong? Thats its one big View instance from OS point of view?
a
It’s true on API 23-27 and API 29+.
u
And flutter doesnt do the same thing? i.e. on big FlutterView where its draws by opengl or whatever they do
a
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
yea btw isnt canvas implemented in skia?
a
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
@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
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
So…Skia everywhere 😅
r
More or less yes. Skia came from Android so it makes sense we and other google teams use it
👍 2
Chrome uses Skia too