[Android] 017. Typography(Text Style)

compose-bomを2024.08にしたら?なんかTextが中央に表示されてないような?みたいな違和感があったので調べてみました

テキストスタイルまわりは以下
https://developer.android.com/develop/ui/compose/text/style-paragraph

PlatformTextStyleが微妙に高さに影響してたようです
ProvideTextStyleとかで全体的に指定をしておいた方がいいかもしれません

@Composable
fun Screen(modifier: Modifier = Modifier) {
    @Composable
    fun TestText(content: @Composable (RowScope.() -> Unit)) {
        Row(
            Modifier
                .background(Color(0.95f, 0.5f, 0.5f, 1.0f))
                .drawWithCache {
                    onDrawBehind {
                        val center = this.size.height / 2
                        drawLine(Color.LightGray, Offset(0.0f, center), Offset(this.size.width, center))
                    }
                },
            verticalAlignment = Alignment.CenterVertically
        ) {
            Box(Modifier.size(9.dp).background(Color.Black))
            content()
            Box(Modifier.size(9.dp).background(Color.Black))
        }
    }

    Column(
        modifier,
        verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        Row(horizontalArrangement = Arrangement.spacedBy(2.dp)) {
            TestText { Text("あいうabc") }
            TestText { Text("あいうabc", style = LocalTextStyle.current.copy(platformStyle = PlatformTextStyle(includeFontPadding = true))) }
            TestText { Text("あいうabc", style = LocalTextStyle.current.copy(
                lineHeight = 32.sp,
                platformStyle = PlatformTextStyle(includeFontPadding = false),
                lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None)
            )) }
        }
    }
}

Android Studio Koala 2024.1.1 Patch 1 built on July 11, 2024