Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[appwidget-host] Improve compatibility with PagerApi #7

Closed
ergofriend opened this issue Oct 10, 2022 · 2 comments
Closed

[appwidget-host] Improve compatibility with PagerApi #7

ergofriend opened this issue Oct 10, 2022 · 2 comments
Labels

Comments

@ergofriend
Copy link

ergofriend commented Oct 10, 2022

Describe the bug

Render GlanceAppWidgetHostPreview on the page element of Pager, nothing appears on the page it was hidden.
However, when I manually click on the element, it seems to reappear when the updateContent() specified for clickable is called.

To Reproduce

use GlanceAppWidgetHostPreview in HorizontalPager's page content

HorizontalPager(
            ...
        ) { page ->
            GlanceAppWidgetHostPreview()
}
screen-20221010-185355_2.mp4

Expected behavior

From the above event, I know that could display it by manually calling updateContent().
So I delayed updateContent() by 100 millis when it was mounted, and the element was always displayed before and after paging.

glance-experimental-tools/GlanceAppWidgetHostPreview.kt at b903edb88c898ca36c4a1b5099c2ebebd32ec6c9 · google/glance-experimental-tools

 if (hostState.isReady) {
   LaunchedEffect(hostState.value) {
+    delay(100)
     updateContent()
  }
}
screen-20221010-185448_2.mp4

Environment:

compose_version = '1.2.1'
androidx.glance:glance-appwidget:1.0.0-alpha04
com.google.android.glance.tools:appwidget-configuration:0.2.2
com.google.accompanist:accompanist-pager:0.26.5-rc
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@b4rd
Copy link

b4rd commented Nov 19, 2022

As a workaround I use runBlocking instead of LaunchedEffect.

Adding the following to AppWidgetHost also worked, but probably this isn't the right fix and the issue is rather related to how lazy composables and AndroidView interact.

update = { hostView ->
    if (hostView != state.value) {
        if (state.providerInfo != null) {
            hostView.setAppWidget(index, state.providerInfo)
            hostView.setPadding(0, 0, 0, 0)
        } else {
            // When no provider is provided, use a fake provider workaround to init the host
            hostView.setFakeAppWidget()
        }
    }
+    state.snapshot?.let {
+        hostView.updateAppWidget(it)
+    }
    state. Value = hostView
}
            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants