mikepenz/Android-Iconics

Compose Image is ignoring `size` modifier

開放

#638 建立於 2023年10月16日

 (1 則留言) (0 個反應) (0 位負責人)Kotlin (613 個分叉)batch import
help wanted

倉庫指標

星標
 (5,277 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

About this issue

For the following composable

@Composable
fun RIcon(
    icon: IIcon,
    modifier: Modifier = Modifier,
    size: Dp = Size.icon,
    color: Color = Color.Unspecified,
    respectFontBounds: Boolean = false, // needed to align some icons correctly
) {
    Image(
        asset = icon,
        modifier = modifier.requiredSizeIn(maxWidth = size, maxHeight = size),
        alignment = Alignment.Center,
        contentScale = ContentScale.Fit,
        iconicsConfig = IconicsConfig(
            respectFontBounds = respectFontBounds,
            iconBrush = SolidColor(color.takeOrElse { LocalContentColor.current }),
            paddingDp = 1,
        ),
    )
}

When using sizeIn(maxWidth, maxHeight), the modifier is ignored and icons spill outside of the composable bounds.requiredSizeIn fixes the issue but breaks animations & other Material widgets that want to resize the icon composable.
We need a proper solution for sizing icons without using requiredSize.

Why is this and how can this be fixed? Using respectFontBounds = true is not possible because that breaks alignment of icons in the container.

Details

  • [x] Used library version 5.5.0-compose01
  • [x] Other used libraries, potential conflicting libraries - compose-material-3 v1.2.0-alpha09, compose 1.6.0-alpha07

Checklist

貢獻者指南