79136607

Date: 2024-10-29 09:51:29
Score: 1.5
Natty:
Report link

I have found a smooth solution, thanks to @JanBína, using Size.Exact

class AppWidget : GlanceAppWidget() {

override val sizeMode = SizeMode.Exact

override suspend fun provideGlance(context: Context, id: GlanceId) {
    provideContent {
        MyContent(context)
    }
}

@Composable
private fun MyContent(context: Context) {
    val size = LocalSize.current

    Log.d("WidgetContent", "Size: $size")
    
    WidgetContent()
}
}

Log while resizing the widget:

WidgetContent D Size: 160.0.dp x 176.0.dp

WidgetContent D Size: 248.0.dp x 176.0.dp

WidgetContent D Size: 336.0.dp x 176.0.dp

WidgetContent D Size: 336.0.dp x 272.0.dp

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @JanBína
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Yazan