diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/ImageBlockScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/ImageBlockScreen.kt index 7670e407d..a2e51e2a8 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/ImageBlockScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/ImageBlockScreen.kt @@ -21,4 +21,3 @@ fun ImageBlockScreen() { @Composable private fun provideSampleImage(): Painter = painterResource("drawable/sample.png") - diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlock.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlock.kt index af02e2307..dc4c75e4e 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlock.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlock.kt @@ -1,7 +1,6 @@ package org.hisp.dhis.mobile.ui.designsystem.component import androidx.compose.foundation.Image -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -16,7 +15,6 @@ import androidx.compose.runtime.produceState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.testTag @@ -44,22 +42,22 @@ fun ImageBlock( downloadButtonVisible: Boolean = true, onClick: () -> Unit, ) { - Box( - modifier = modifier - .padding(vertical = Spacing.Spacing8) - .testTag("IMAGE_BLOCK_CONTAINER"), - ) { - val image: T? by produceState(null) { - value = withContext(Dispatchers.IO) { - try { - load() - } catch (e: IOException) { - null - } + val image: T? by produceState(null) { + value = withContext(Dispatchers.IO) { + try { + load() + } catch (e: IOException) { + null } } + } - if (image != null) { + if (image != null) { + Box( + modifier = modifier + .padding(vertical = Spacing.Spacing8) + .testTag("IMAGE_BLOCK_CONTAINER"), + ) { Image( painter = painterFor(image!!), contentDescription = null, @@ -67,23 +65,23 @@ fun ImageBlock( modifier = Modifier .fillMaxWidth() .clip(shape = RoundedCornerShape(Radius.S)) - .height(160.dp) + .height(160.dp), ) - } - if (downloadButtonVisible) { - SquareIconButton( - enabled = true, - modifier = Modifier - .align(Alignment.BottomEnd) - .padding(Spacing.Spacing4), - icon = { - Icon( - imageVector = Icons.Outlined.FileDownload, - contentDescription = "File download Button", - ) - }, - ) { - onClick.invoke() + if (downloadButtonVisible) { + SquareIconButton( + enabled = true, + modifier = Modifier + .align(Alignment.BottomEnd) + .padding(Spacing.Spacing4), + icon = { + Icon( + imageVector = Icons.Outlined.FileDownload, + contentDescription = "File download Button", + ) + }, + ) { + onClick.invoke() + } } } } diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlockTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlockTest.kt index c9ff845fa..aa1d0b43f 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlockTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/ImageBlockTest.kt @@ -1,7 +1,9 @@ package org.hisp.dhis.mobile.ui.designsystem.component +import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag +import org.hisp.dhis.mobile.ui.designsystem.component.internal.image.provideImage import org.junit.Rule import org.junit.Test import java.io.File @@ -14,7 +16,11 @@ class ImageBlockTest { @Test fun shouldNotRenderImageBlockIfFileIsNotValid() { rule.setContent { - ImageBlock(file = File("")) {} + ImageBlock( + load = { provideImage(File("")) }, + painterFor = { BitmapPainter(it!!) }, + onClick = {}, + ) } rule.onNodeWithTag("IMAGE_BLOCK_CONTAINER").assertDoesNotExist()