Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

fix: adjust image corner radius #1552

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import br.com.zup.beagle.android.engine.mapper.ViewMapper
import br.com.zup.beagle.android.imagedownloader.DefaultImageDownloader
import br.com.zup.beagle.android.logger.BeagleMessageLogs
import br.com.zup.beagle.android.setup.BeagleEnvironment
import br.com.zup.beagle.android.utils.dp
import br.com.zup.beagle.android.utils.observeBindChanges
import br.com.zup.beagle.android.view.ViewFactory
import br.com.zup.beagle.android.widget.RootView
Expand Down Expand Up @@ -73,11 +74,15 @@ data class Image constructor(
}

private fun getImageView(rootView: RootView) = viewFactory.makeImageView(rootView.getContext(),
style?.cornerRadius?.radius ?: 0.0).apply {
getCornerRadius()).apply {
adjustViewBounds = true
scaleType = viewMapper.toScaleType(mode ?: ImageContentMode.FIT_CENTER)
}

private fun getCornerRadius(): Double {
return style?.cornerRadius?.radius?.dp() ?: 0.0
}

private fun loadLocalImage(rootView: RootView, imageView: ImageView, pathType: ImagePath.Local) {
imageView.apply {
observeBindChanges(rootView, imageView, pathType.mobileId) { mobileId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import android.widget.ImageView
import br.com.zup.beagle.android.components.utils.RoundedImageView
import br.com.zup.beagle.android.setup.BeagleEnvironment
import br.com.zup.beagle.android.testutil.RandomData
import br.com.zup.beagle.android.utils.dp
import br.com.zup.beagle.android.view.ViewFactory
import br.com.zup.beagle.core.CornerRadius
import br.com.zup.beagle.core.Style
import br.com.zup.beagle.ext.applyStyle
import br.com.zup.beagle.ext.unitReal
Expand All @@ -30,6 +32,7 @@ import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.verify
import org.junit.jupiter.api.Assertions.assertEquals
Expand All @@ -47,7 +50,8 @@ internal class ImageTest : BaseComponentTest() {

private val imageView: RoundedImageView = mockk(relaxed = true, relaxUnitFun = true)
private val scaleTypeSlot = slot<ImageView.ScaleType>()
private val style = Style(size = Size(width = 100.unitReal(), height = 100.unitReal()))
private val style = Style(size = Size(width = 100.unitReal(), height = 100.unitReal()),
cornerRadius = CornerRadius(radius = 10.0))

private lateinit var imageLocal: Image
private lateinit var imageRemote: Image
Expand All @@ -57,9 +61,12 @@ internal class ImageTest : BaseComponentTest() {
override fun setUp() {
super.setUp()

mockkStatic("br.com.zup.beagle.android.utils.NumberExtensionsKt")

every { anyConstructed<ViewFactory>().makeImageView(rootView.getContext(), any()) } returns imageView
every { beagleSdk.designSystem } returns mockk(relaxed = true)
every { beagleSdk.designSystem!!.image(any()) } returns IMAGE_RES
every { 10.0.dp() } returns 20.0

imageLocal = Image(ImagePath.Local("imageName"))
imageRemote = Image(ImagePath.Remote(DEFAULT_URL, ImagePath.Local("imageName"))).applyStyle(style)
Expand Down Expand Up @@ -169,5 +176,17 @@ internal class ImageTest : BaseComponentTest() {
// Then
verify(exactly = 1) { imageView.setImageResource(IMAGE_RES) }
}

@Test
@DisplayName("Then set corner radius correctly")
fun testCornerRadius() {
// When
imageRemote.buildView(rootView)

// Then
verify {
anyConstructed<ViewFactory>().makeImageView(rootView.getContext(), 20.0)
}
}
}
}