Last active
August 26, 2022 08:59
-
-
Save marcelpinto/e4d41de71a8249ac5b72d764e45acf86 to your computer and use it in GitHub Desktop.
AppWidgetHost example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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