Zach Klippenstein (he/him) [MOD]
04/19/2021, 5:32 PMSiyamed
04/19/2021, 5:36 PMSiyamed
04/19/2021, 5:36 PMZach Klippenstein (he/him) [MOD]
04/19/2021, 5:37 PMSiyamed
04/19/2021, 5:39 PMromainguy
04/19/2021, 5:41 PMromainguy
04/19/2021, 5:41 PMSiyamed
04/19/2021, 5:41 PMromainguy
04/19/2021, 5:41 PMPath
outline of a chunk of textromainguy
04/19/2021, 5:41 PMPath
and vary the stroke width smoothlySiyamed
04/19/2021, 5:42 PMZach Klippenstein (he/him) [MOD]
04/19/2021, 5:52 PMBut you can request theThat’s an Android-specific api, not Compose, right?outline of a chunk of textPath
Zach Klippenstein (he/him) [MOD]
04/19/2021, 6:15 PMval variableFont = remember { FontFamily(Font(R.raw.variable_font)) }
val animatedWeight by rememberInfiniteTransition()
.animateFloat(
initialValue = 1f, targetValue = 1000f,
infiniteRepeatable(tween(5000), repeatMode = Reverse)
)
Text(
"Weight: ${animatedWeight.toInt()}",
fontWeight = FontWeight(animatedWeight.toInt()),
fontFamily = variableFont
)
Anyhoo, thanks for the idea @romainguy!Albert Chang
04/23/2021, 4:41 PMtextView.fontVariationSettings = "'wght' 150"
, in which fontVariationSettings
isn't used in typeface resolving and is instead set on the underlying TextPaint
. This is the reason why directly setting font weight won't work. In Compose UI we can set fontFeatureSettings
through TextStyle
and it'll be nice if we can also set fontVariationSettings
.Albert Chang
04/23/2021, 4:44 PMAndroidView
to animate font weight.
val weight by rememberInfiniteTransition().animateFloat(
initialValue = 1f,
targetValue = 1000f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 2000,
easing = LinearEasing
),
repeatMode = RepeatMode.Reverse
)
)
AndroidView(
factory = {
TextView(it).apply {
text = "Animated Weight"
setTextSize(TypedValue.COMPLEX_UNIT_SP, 80f)
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
},
modifier = Modifier.fillMaxWidth()
) {
it.fontVariationSettings = "'wght' ${weight.toInt()}"
}
Note that fontVariationSettings
is only available on API 26+ and Android 12 starts to use variable fonts as system fonts.Zach Klippenstein (he/him) [MOD]
04/23/2021, 4:58 PMfontVariationSettings
in the Compose API?Zach Klippenstein (he/him) [MOD]
04/23/2021, 5:05 PMAlbert Chang
04/24/2021, 6:05 AM