Skip to content

Commit 487ac6f

Browse files
florentmaitrepaulinea
authored andcommitted
Various minor fixes
1 parent 3f222a5 commit 487ac6f

3 files changed

Lines changed: 20 additions & 36 deletions

File tree

core/src/main/java/com/orange/ouds/core/component/OudsListItem.kt

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import androidx.compose.ui.Modifier
4242
import androidx.compose.ui.draw.clip
4343
import androidx.compose.ui.graphics.Color
4444
import androidx.compose.ui.graphics.ImageBitmap
45-
import androidx.compose.ui.graphics.Shape
4645
import androidx.compose.ui.graphics.painter.Painter
4746
import androidx.compose.ui.graphics.vector.ImageVector
4847
import androidx.compose.ui.layout.ContentScale
@@ -263,7 +262,7 @@ internal fun OudsListItem(
263262

264263
with(OudsTheme.components.listItem) {
265264
val borderRadius = if (card && LocalThemeSettings.current.roundedCornerCardItems == true) border.radius.rounded else border.radius.default
266-
val shape = shape(borderRadius)
265+
val shape = shape(cornerRadius = borderRadius)
267266

268267
val clickableModifier = if (onClick != null) {
269268
Modifier.clickable(
@@ -284,7 +283,7 @@ internal fun OudsListItem(
284283
.fillMaxWidth()
285284
.heightIn(min = minHeight(size))
286285
.background(color = backgroundColor.value, shape = shape)
287-
.border(state = state, decoration = decoration, shape = shape, borderRadius = borderRadius, outlineColor = outlineBorderColor.value)
286+
.border(state = state, decoration = decoration, cornerRadius = borderRadius, outlineColor = outlineBorderColor.value)
288287
.outerBorder(state = state, shape = shape)
289288
.containerPadding(size = size, verticalAlignment = verticalAlignment)
290289
.semantics(mergeDescendants = true) { },
@@ -423,32 +422,23 @@ private fun backgroundColor(state: OudsListItemState, decoration: OudsListItemDe
423422
}
424423

425424
@Composable
426-
private fun Modifier.border(state: OudsListItemState, decoration: OudsListItemDecoration, shape: Shape, borderRadius: Dp, outlineColor: Color): Modifier {
427-
val outlined: Boolean
428-
when (decoration) {
429-
is OudsListItemDecoration.Outlined -> {
430-
outlined = true
431-
}
432-
is OudsListItemDecoration.OutlinedOnInteraction -> {
433-
outlined = state in listOf(OudsListItemState.Hovered, OudsListItemState.Pressed, OudsListItemState.Focused)
434-
}
435-
is OudsListItemDecoration.Background,
436-
is OudsListItemDecoration.BackgroundOnInteraction,
437-
is OudsListItemDecoration.None -> {
438-
outlined = false
439-
}
440-
}
425+
private fun Modifier.border(state: OudsListItemState, decoration: OudsListItemDecoration, cornerRadius: Dp, outlineColor: Color): Modifier {
426+
val outlined = decoration is OudsListItemDecoration.Outlined || (decoration is OudsListItemDecoration.OutlinedOnInteraction && state in listOf(
427+
OudsListItemState.Hovered,
428+
OudsListItemState.Pressed,
429+
OudsListItemState.Focused
430+
))
441431
val width = OudsTheme.borders.width.default.takeUnlessHairline
442432

443433
return when {
444-
width != null && outlined -> border(width = width, color = outlineColor, shape = shape)
445-
width != null && decoration.divider -> bottomBorder(width = width, color = OudsTheme.colorScheme.border.muted, cornerRadius = borderRadius)
434+
width != null && outlined -> border(width = width, color = outlineColor, shape = shape(cornerRadius = cornerRadius))
435+
width != null && decoration.divider -> bottomBorder(width = width, color = OudsTheme.colorScheme.border.muted, cornerRadius = cornerRadius)
446436
else -> this
447437
}
448438
}
449439

450440
@Composable
451-
private fun shape(borderRadius: Dp) = RoundedCornerShape(borderRadius)
441+
private fun shape(cornerRadius: Dp) = RoundedCornerShape(cornerRadius)
452442

453443
@Composable
454444
private fun outlineBorderColor(state: OudsListItemState) = with(OudsTheme.colorScheme.action) {
@@ -785,18 +775,12 @@ open class OudsListItemImage internal constructor(
785775

786776
@Composable
787777
override fun Content(modifier: Modifier) {
778+
val cornerRadius = with(OudsTheme.components.listItem.border.radius) { if (roundedCorner) mediaRounded else media }
788779
super.Content(
789780
modifier = modifier
790781
.height(size.value)
791782
.width(size.value * ratio.value)
792-
.run {
793-
if (roundedCorner) {
794-
clip(RoundedCornerShape(OudsTheme.components.listItem.border.radius.mediaRounded))
795-
} else {
796-
this
797-
}
798-
}
799-
783+
.clip(RoundedCornerShape(cornerRadius))
800784
)
801785
}
802786
}
@@ -862,7 +846,7 @@ sealed interface OudsListItemLeading : OudsListItemLeadingTrailing {
862846
constructor(
863847
painter: Painter,
864848
contentDescription: String,
865-
size: OudsListItemIconSize = OudsListItemIconSize.Medium,
849+
size: OudsListItemIconSize = OudsListItemDefaults.IconSize,
866850
tinted: Boolean = true
867851
) : this({ painter as Any }, { contentDescription }, tinted, size, null)
868852

@@ -879,7 +863,7 @@ sealed interface OudsListItemLeading : OudsListItemLeadingTrailing {
879863
constructor(
880864
imageVector: ImageVector,
881865
contentDescription: String,
882-
size: OudsListItemIconSize = OudsListItemIconSize.Medium,
866+
size: OudsListItemIconSize = OudsListItemDefaults.IconSize,
883867
tinted: Boolean = true
884868
) : this({ imageVector as Any }, { contentDescription }, tinted, size, null)
885869

@@ -896,7 +880,7 @@ sealed interface OudsListItemLeading : OudsListItemLeadingTrailing {
896880
constructor(
897881
bitmap: ImageBitmap,
898882
contentDescription: String,
899-
size: OudsListItemIconSize = OudsListItemIconSize.Medium,
883+
size: OudsListItemIconSize = OudsListItemDefaults.IconSize,
900884
tinted: Boolean = true
901885
) : this({ bitmap as Any }, { contentDescription }, tinted, size, null)
902886

core/src/main/java/com/orange/ouds/core/component/OudsSmallListItem.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ sealed interface OudsSmallListItemLeading : OudsListItemLeadingTrailing {
270270
class Image internal constructor(
271271
graphicsObject: Any,
272272
contentDescription: String,
273-
imageFormat: OudsListItemImageRatio,
273+
ratio: OudsListItemImageRatio,
274274
contentScale: ContentScale,
275275
roundedCorner: Boolean
276-
) : OudsListItemImage(graphicsObject, contentDescription, SmallListItemAssetSize, imageFormat, contentScale, roundedCorner), OudsSmallListItemLeading {
276+
) : OudsListItemImage(graphicsObject, contentDescription, SmallListItemAssetSize, ratio, contentScale, roundedCorner), OudsSmallListItemLeading {
277277

278278
/**
279279
* Creates an instance of [OudsSmallListItemLeading.Image].
@@ -418,10 +418,10 @@ sealed interface OudsSmallListItemTrailing : OudsListItemLeadingTrailing {
418418
class Image internal constructor(
419419
graphicsObject: Any,
420420
contentDescription: String,
421-
imageFormat: OudsListItemImageRatio,
421+
ratio: OudsListItemImageRatio,
422422
contentScale: ContentScale,
423423
roundedCorner: Boolean
424-
) : OudsListItemImage(graphicsObject, contentDescription, SmallListItemAssetSize, imageFormat, contentScale, roundedCorner), OudsSmallListItemTrailing {
424+
) : OudsListItemImage(graphicsObject, contentDescription, SmallListItemAssetSize, ratio, contentScale, roundedCorner), OudsSmallListItemTrailing {
425425

426426
/**
427427
* Creates an instance of [OudsSmallListItemTrailing.Image].
285 Bytes
Loading

0 commit comments

Comments
 (0)