How does jetpack compose work under the hood

雨燕双飞 提交于 2020-02-25 04:13:33

问题


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?


回答1:


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).




回答2:


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



来源:https://stackoverflow.com/questions/58558163/how-does-jetpack-compose-work-under-the-hood

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!