Stylianos Gakis
Stylianos Gakis

Reputation: 1023

Can Jetpack Compose be used to build App Widgets?

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?

Upvotes: 21

Views: 6004

Answers (4)

Westy92
Westy92

Reputation: 21265

You can use AndroidX's Glance, which is now an Alpha release:

https://developer.android.com/jetpack/androidx/releases/glance

You can find an example code project here:

https://github.com/android/user-interface-samples/tree/glance/AppWidget/glance-widget

Upvotes: 9

Stylianos Gakis
Stylianos Gakis

Reputation: 1023

Turns out this is something that is not possible yet, but it's in the works.

According to this video at 12:16 onwards by the Android Developers YouTube channel, this is currently an idea that is being explored to be released later this year (2021).

An example of how it may look like is this (Taken directly from the same video):

Conceptual code showing how building Widgets with Compose might look like

Upvotes: 7

Noel Chew
Noel Chew

Reputation: 3933

Updated Nov 08, 2021: New Jetpack library GlanceAppWidget as mentioned in this video. Could not find more information on Glance at time of writing.

Saw this post by Google. Looking forward to more announcements! enter image description here

Link: https://developer.android.com/jetpack/androidx/compose-roadmap

Upvotes: 13

CommonsWare
CommonsWare

Reputation: 1006594

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.

Upvotes: 14

Related Questions