composeForPreview

Function
Android
public suspend fun GlanceAppWidget.composeForPreview(
    context: Context,
    widgetCategory: Int,
    info: AppWidgetProviderInfo? = null,
): RemoteViews

Runs the composition in GlanceAppWidget.providePreview one time and translate it to a RemoteViews. This function can be used to test the preview layout of a GlanceAppWidget.

The value of androidx.glance.LocalSize in the composition depends on the value of GlanceAppWidget.previewSizeMode:

If using SizeMode.Single (default), the composition will use the minimum size of the widget as determined by its AppWidgetProviderInfo.minHeight and AppWidgetProviderInfo.minWidth. If info is null, then DpSize.Zero will be used.

If using SizeMode.Responsive, the composition will use the provided sizes.

The given widgetCategory value should be a combination of AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN, AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD, or AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX.

Parameters

context context to provide to GlanceAppWidget.providePreview
widgetCategory widget category to provide to GlanceAppWidget.providePreview
info the size of the composition is determined by the minimum width defined in this AppWidgetProviderInfo

Returns

the preview composition translated to a RemoteViews