Skip to content

Commit

Permalink
Add condition when clicking an image
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Feb 13, 2024
1 parent e0d88fa commit e2b9fb6
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.smartregister.fhircore.quest.ui.shared.components

import android.content.Context
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -73,6 +74,7 @@ fun Image(
) {
val imageConfig = imageProperties.imageConfig
val colorTint = tint ?: imageProperties.imageConfig?.color.parseColor()
val cotext = LocalContext.current
if (imageConfig != null) {
if (imageProperties.text != null) {
Row(
Expand All @@ -93,6 +95,7 @@ fun Image(
navController = navController,
resourceData = resourceData,
modifier = modifier,
context = cotext,
)
}
} else {
Expand All @@ -104,6 +107,7 @@ fun Image(
navController = navController,
resourceData = resourceData,
modifier = modifier,
context = cotext,
)
}
}
Expand All @@ -118,6 +122,7 @@ fun ClickableImageIcon(
paddingEnd: Int?,
navController: NavController,
resourceData: ResourceData? = null,
context: Context? = null,
) {
Box(
contentAlignment = Alignment.Center,
Expand All @@ -138,16 +143,19 @@ fun ClickableImageIcon(
{ background(imageProperties.backgroundColor.parseColor()) },
)
.conditional(imageProperties.padding >= 0, { padding(imageProperties.padding.dp) })
.clickable(
onClick = {
if (imageProperties.visible.toBoolean() && imageProperties.clickable.toBoolean()) {
imageProperties.actions.handleClickEvent(
navController = navController,
resourceData = resourceData,
context = null,
)
}
},
.conditional(
imageProperties.clickable.toBoolean() && imageProperties.visible.toBoolean(),
{
clickable(
onClick = {
imageProperties.actions.handleClickEvent(
navController = navController,
resourceData = resourceData,
context = context,
)
},
)
}
),
) {
when (imageConfig.type) {
Expand Down

0 comments on commit e2b9fb6

Please sign in to comment.