platform-samples icon indicating copy to clipboard operation
platform-samples copied to clipboard

Fix corner radius for Glance app widget background

Open valentinilk opened this issue 1 year ago • 1 comments

The cornerRadius modifiers included in appWidgetBackgroundCornerRadius() and appWidgetInnerCornerRadius() where actually never applied to the widget. The CombinedGlanceModifier created by the cornerRadius functions was only ever created, but was never be made part of the modifier chain.

This can be seen by comparing the Glance widget (bottom) to the legacy one (on top), where the system's radius is applied correctly:

After the fix it will look like this:

Unfortunately the fix reveals a bug in Glance. If you select the widget by using a long press, you can see that the system still thinks that the smaller radius is applied. The small radius is probably the fallback radius of 16 dp. I'll wait with the bug report until this PR is merged, so I can provide this project as a sample.

valentinilk avatar Sep 20 '23 14:09 valentinilk

Hi!

Thanks for your PR, apply the following patch to your code to fix the glance corner radius and I will merge.

From 6980289919901279d73148a3981d1a10e926d3d4 Mon Sep 17 00:00:00 2001
From: Summers Pittman <[email protected]>
Date: Fri, 8 Dec 2023 10:25:49 -0500
Subject: [PATCH] fixing radius

---
 .../com/example/platform/ui/appwidgets/glance/GlanceKtx.kt     | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/GlanceKtx.kt b/samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/GlanceKtx.kt
index 0d9d461..1762029 100644
--- a/samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/GlanceKtx.kt
+++ b/samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/GlanceKtx.kt
@@ -75,13 +75,12 @@ fun AppWidgetColumn(
 fun appWidgetBackgroundModifier() = GlanceModifier
     .fillMaxSize()
     .padding(16.dp)
-    .appWidgetBackground()
     .background(GlanceTheme.colors.background)
     .appWidgetBackgroundCornerRadius()
 
 fun GlanceModifier.appWidgetBackgroundCornerRadius(): GlanceModifier =
     if (Build.VERSION.SDK_INT >= 31) {
-        cornerRadius(android.R.dimen.system_app_widget_background_radius)
+        this.appWidgetBackground()
     } else {
         cornerRadius(16.dp)
     }
-- 
2.43.0.472.g3155946c3a-goog

secondsun avatar Dec 08 '23 15:12 secondsun