Jetpack glance widget only the whitespace is clickable, text and image are not

743 Views Asked by At

I have a glance widget that contains a column. The column has tiles containing text and image. The row has clickable modifier, however, I can click only the whitespace. Any way to solve this?

There is a similar question however the answer to it suggests reverting to alpha-03 but I have alpha-05 which I believe the bug should be solved.

Sample code:

Column(
        modifier = GlanceModifier
            .fillMaxSize()
            .cornerRadiusCompat(
                cornerRadius = 16,
                color = if(uiState.isDark)
                    LocalContext.current.getColor(R.color.dark_list_widget_background_color)
                else
                    LocalContext.current.getColor(R.color.light_list_widget_background_color)
            )
    ) {
        ListWidgetHeader(
            isDark = uiState.isDark,
            type = uiState.type
        )
        Box(
            modifier = GlanceModifier
                .fillMaxSize()
                .background(
                    if (uiState.isDark)
                        R.color.dark_list_widget_background_color
                    else
                        R.color.light_list_widget_background_color
                ),
            contentAlignment = Alignment.Center
        ) {
            ListWidgetContent(
                data = uiState.data,
                isDark = uiState.isDark,
                type = uiState.type
            )
        }
    }

@Composable
private fun ListWidgetContent(
    data: List<ListWidgetData>,
    isDark: Boolean,
    type: WidgetCategoryEnum
) {
    Column{
        data.forEachIndexed { index, model ->
            ListWidgetTile(
                model = model,
                isDark = isDark,
                bottomPadding = 16.dp,
                topPadding = if (index == 0) 16.dp else 0.dp,
                type = type
            )
        }
    }
}

@Composable
private fun ListWidgetTile(
    model: ListWidgetData,
    isDark: Boolean,
    bottomPadding: Dp,
    topPadding: Dp,
    type: WidgetCategoryEnum,
) {
    val action = // Some Action related to app-logic
    val intent = Intent(
        Intent.ACTION_VIEW,
        "${URL}/${Screens.Splash.navigateWithDeepLink(DeepLinkModel(model.id, action))}".toUri()
    )
    val bitmap = if(model.image != "") {
        model.image.decodeToBase64()
    } else {
        null
    }
    Row(
        modifier = GlanceModifier
            .fillMaxWidth()
            .padding(
                start = 24.dp,
                end = 15.dp,
                bottom = bottomPadding,
                top = topPadding
            )
            .clickable(
                actionStartActivity(intent)
            ) // WORKS ONLY IN WHITESPACE
    ) {
        Column(
            modifier = GlanceModifier
                .fillMaxWidth()
                .defaultWeight()
                .padding(
                    end = 8.dp
                )
                .clickable(
                    actionStartActivity(intent)
                ) // NOT WORKS
        ) {
            Text(
                text = model.source,
                style = TextStyle(
                    fontSize = 8.sp,
                    fontWeight = FontWeight.Medium,
                    color = ColorProvider(
                        resId = if (isDark)
                            R.color.dark_list_widget_source_time_color
                        else
                            R.color.light_list_widget_source_time_color
                    )
                ),
                modifier = GlanceModifier
                    .padding(
                        bottom = 8.dp
                    )
            )
            Text(
                text = model.title,
                style = TextStyle(
                    fontSize = 16.sp,
                    fontWeight = FontWeight.Bold,
                    color = ColorProvider(
                        resId = if (isDark)
                            R.color.dark_list_widget_title_color
                        else
                            R.color.light_list_widget_title_color
                    )
                ),
                maxLines = 3,
            )
        }
        if (bitmap != null) {
            Image(
                provider = ImageProvider(
                    bitmap
                ),
                contentDescription = "Image",
                modifier = GlanceModifier
                    .size(70.dp)
                    .imageCornerRadius(),
                contentScale = ContentScale.Crop
            )
        }
    }
}
0

There are 0 best solutions below