Can Jetpack Compose be used to build App Widgets?

一个人想着一个人 提交于 2020-12-09 16:27:07

问题


With swift, widgets can be written using SwiftUI, but I have not seen any statements regarding whether Jetpack Compose can be used to build Android App Widgets.

Is there any information where I can see how that can be done now that Compose is in Alpha?


回答1:


That depends a lot on what you mean by "Jetpack Compose". We were discussing this just yesterday on Kotlinlang Slack.

If you mean Compose UI and related packages — the library of composables that we can use to build the UIs displayed by activities — then no, this will have little role with app widgets. You could, in principle, render a composable to a Bitmap, then use that with an ImageView in an app widget, but that's about it.

If you mean Compose Runtime — the underlying "plumbing" behind @Composable, recomposition, remember(), and so on — then there may be something offered in the future. Basically, as I understand it, there might be another set of composables tied to building up and publishing a RemoteViews view hierarchy. On the plus side, this will give your AppWidgetProvider a Compose "feel". However, it will not cause something like TextField to start working magically in an app widget.



来源:https://stackoverflow.com/questions/63635264/can-jetpack-compose-be-used-to-build-app-widgets

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