喷气背包如何在引擎盖下工作 [英] How does jetpack compose work under the hood

查看:32
本文介绍了喷气背包如何在引擎盖下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Arch 组件中新增的 Jetpack compose 组件就像 Flutter Ui 制作一样.

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

它是如何制作用户界面的?

是使用了Skia这样的原生代码引擎,还是还是像以前一样遵循ViewGroup的方式?

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

推荐答案

Compose 创建一个当前名为 AndroidComposeView 的视图,它继承了 ViewGroup,并在其画布上绘制了小部件树.它还处理此视图的运动/键盘事件.

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.

由于实现细节,可能会有更多的辅助视图添加到此视图中,但基本上对于 Compose 的小部件",您不会在视图层次结构中看到经典视图.布局检查器目前对 Compose 没有帮助 - 您可以尝试一下,但不会看到您的小部件.

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.

承诺开发者能够创建自己的自定义小部件,这些小部件可以直接在 Canvas 上绘制、为自身或子项设置布局或处理输入事件.

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.

然而,Canvas 和这里使用的许多其他类都不是标准的框架类.例如,Canvas for Compose 在 Kotlin 中重新定义.类似的方式还有新的 PaintShape 和其他新类.他们在内部使用框架类进行工作,但这是实现细节.绘图时,您将使用这些新类.

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.

由于 Compose 是一个库,而不是原生在 Android 设备上,因此该库包含在每个使用 Compose 的应用中.此外,这里不涉及本机代码,所有内容都在 Kotlin 中完成,并成为您应用的 dexed 代码的一部分.通过使用 Compose,您的应用将不会包含任何额外的原生库(可能,如果创作者不改变主意的话).

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

这篇关于喷气背包如何在引擎盖下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆