https://kotlinlang.org logo
#compose
Title
# compose
m

mzgreen

10/25/2019, 4:54 AM
How does Compose relate to current View system? I mean, Android UI Compose. Is there somewhere down the stack an actual Android View used? From the ADS talk I assume that for at least some of the components there is (for example WebView, MapView maybe TextView?). If so then where is this layer in the stack that was showed on ADS presentation? Are there Compose Components that are completely independent of current View system that are written completely from scratch using Compose? And last question is about @GenerateView annotation - what does it do? Does it translate Compose code into View code under the hood? Or maybe it generates an xml or something?
g

gildor

10/25/2019, 5:01 AM
Are there Compose Components that are completely independent of current View system that are written completely from scratch using Compose?
Yes, most of them, except very complex like WebView and MapView
Text component has own implementation
m

mzgreen

10/25/2019, 5:07 AM
Thanks! If some of Compose components are using Views under the hoods, then I guess I’ll be another way to do a step by step migration of an existing app to Compose. For going Compose->View there is @GenerateView but as mentioned in ADS talk we need a mechanism that can do it in the opposite way View->Compose. So if there is an API that allows to easily create a Compose component that uses a View under the hoods then we could use that maybe.
g

gildor

10/25/2019, 5:35 AM
using Views under the hoods
They do not use Views under the hood, it’s just a way to render Android view as part of Composable components
👍 1
we need a mechanism that can do it in the opposite way View->Compose
It’s already supported on some level, at least some exdperiments with it, you can find adapters on official Compose samples
1
l

louis993546

10/25/2019, 6:36 AM
You also have to keep in mind that
View -> Compose
means you lost a lot of the goal of “not relying on `View`” (e.g. that custom view has it’s source of truth) might be gone. The existing mechanism of
View -> Compose
seems to be really really really only intended for stuff that uses
SurfaceView
.
g

gildor

10/25/2019, 6:38 AM
It make sense for any complicated View
1
m

mzgreen

10/25/2019, 6:43 AM
Yes I understand that but there are lots of valuable open source projects or even sdks that provide views, so to make adoption faster it would be good to have some temporary way of wrapping existing code so that it becomes Compose friendly.
2
r

romainguy

10/25/2019, 8:03 AM
@louis993546 and custom views you might not want to rewrite
For instance something that draws charts
m

mzgreen

10/25/2019, 9:47 AM
Writing custom views with declarative ui is fun so I suspect there will be a lot of new open source libraries, like it is in Flutter ecosystem. What I like about declarative ui is that if there is some component that doesn’t have the functionality I want, then I can just look what other components it uses under the hoods and go layer by layer until I get to the point where I can reuse everything that sits below and then just write the top layer myself. There is a lot less copying involved compared to inheritance based system we have now.
t

tieskedh

10/25/2019, 10:18 AM
Does this mean that Jetpack Compose isn't a good fit for instant apps?
🤔 1
g

gildor

10/25/2019, 10:19 AM
Why?
t

tieskedh

10/25/2019, 10:27 AM
Flutter brings a complete ecosystem to its aab. which means it takes up a lot of the 4mb allowed. Is this the same with Jetpack Compose?
🚫 1
m

mzgreen

10/25/2019, 10:27 AM
No, it’s just a new UI framework, not a whole rendering engine 🙂
👍🏻 1
t

tieskedh

10/25/2019, 10:28 AM
Ah, great!!! Thx!
r

romainguy

10/25/2019, 11:25 AM
We reuse the rendering engine and text stack of the platform, both contain a large amount of native code.
g

gildor

10/25/2019, 11:26 AM
Also flutter includes whole runtime of Dart, not only rendering engine
m

mzgreen

10/25/2019, 11:58 AM
Yeah so assuming your app doesn't use Kotlin then you have to take Kotlin size into account.
f

Fudge

10/25/2019, 12:12 PM
I thought you didn't need to bundle the stdlib with your app?
g

gildor

10/25/2019, 12:13 PM
You pay only stdlib size (about 1 mb), also it can be significantly reduced with r8
You need, of course
r

Ryan Mentley

10/25/2019, 7:47 PM
You do need the Kotlin stdlib, yes, though Andrey is correct
You should definitely be running minification if you care about APK size, both with and without Compose
m

mzgreen

10/25/2019, 7:49 PM
So going back to my original question - what does @GenerateView do (or will do) under the hoods?
r

Ryan Mentley

10/25/2019, 11:09 PM
The exact details are TBD, but the short answer is "produce a view that renders a Compose hierarchy" - this is how we render our hierarchies today, via
AndroidComposeView
There's no need for any translation, as Compose already renders within the Android View hierarchy
m

mzgreen

10/26/2019, 6:32 AM
Oh I understand, makes sense thank you!
👍 1
4 Views