Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jetpack compose work under the hood

The new Jetpack compose component added to Arch component is like Flutter Ui making.

How does it make the Ui though?

Does it use a native code engine like Skia, or it still follows the ViewGroup way like before?

like image 850
Mahdi-Malv Avatar asked Oct 25 '19 12:10

Mahdi-Malv


People also ask

How does jetpack compose work internally?

Jetpack Compose is a modern declarative UI Toolkit for Android. Compose makes it easier to write and maintain your app UI by providing a declarative API that allows you to render your app UI without imperatively mutating frontend views.

Does jetpack compose use Skia?

Compose for Desktop Features Hardware accelerated rendering with Skia. Powerful text rendering and layout for many languages. Excellent AWT and Swing interoperability. Code sharing with Jetpack Compose Android applications via Kotlin Multiplatform.

What exactly is jetpack compose?

Jetpack Compose is Android's modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.

What does remember do in jetpack compose?

remember can be used to store both mutable and immutable objects. Note: remember stores objects in the Composition, and forgets the object when the composable that called remember is removed from the Composition.


2 Answers

Compose creates one view currently named AndroidComposeView, which inherits ViewGroup, and it draws the widget tree on its canvas. It also processes motion/keyboard events for this view.

There may be more helper views added to this view due to implementation details, but basically for the "widgets" of Compose, you won't see classical Views in view hierarchy. Layout inspector currently doesn't help for Compose - you can try it but you'll won't see your widgets.

Developers are promised to be able to create own customized widgets, which can directly paint on Canvas, set layout for itself or children, or process input events.

However, the Canvas and lots of other classes used here are not standard framework classes. For example, Canvas for Compose is redefined in Kotlin. Similar way there is new Paint, Shape, and other new classes. They internally use framework classes for their work, but that's implementation detail. When drawing, you'd use these new classes.

Since Compose is a library, and not present natively on Android devices, the library is included in each app that uses Compose. Also there is no native code involved here, all is done in Kotlin and becomes part of your app's dexed code. By using Compose, your app won't contain any additional native library (probably, if creators don't change mind).

like image 178
Pointer Null Avatar answered Sep 21 '22 08:09

Pointer Null


No, It doesn't use anything from the old UI Toolkit actually they are building it to overcome old UIToolkit's problems.

Compose is not views, It's a new set of Jetpack UI Widget, Basically, it's a Kotlin compiler plugin which renders the Android Canvas (I suppose there's no documentation for this yet) with full compatibility of existing android's view system, the last Dev summit there was a talk covers how it works internally, I/O had another talk too

like image 41
Sayed El-Abady Avatar answered Sep 20 '22 08:09

Sayed El-Abady