Skip to content

Instantly share code, notes, and snippets.

@marcelpinto
Last active August 26, 2022 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelpinto/e4d41de71a8249ac5b72d764e45acf86 to your computer and use it in GitHub Desktop.
Save marcelpinto/e4d41de71a8249ac5b72d764e45acf86 to your computer and use it in GitHub Desktop.
AppWidgetHost example
/**
* Copyright 2022 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
@Composable
fun MyScreen(glanceAppWidget: GlanceAppWidget) {
val state = rememberAppWidgetHostState()
// the available size for the widget
val size = DpSize(200.dp, 200.dp)
if (previewHostState.isReady) {
// When the host is ready, generate the remote views.
LaunchedEffect(previewHostState.value) {
state.updateAppWidget(
// Extension method that uses GlanceRemoteViews
glanceAppWidget.compose(context, size)
)
}
}
AppWidgetHost(
modifier = Modifier.fillMaxSize(),
widgetSize = size,
state = state
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment