refactor: allow SecondaryText use primaryFontSize and fontSize

This commit is contained in:
2024-01-18 10:15:35 +08:00
parent cc1c5ec0fc
commit 827fa6498a

View File

@@ -194,6 +194,9 @@ fun Text(
* @see Text * @see Text
* @param text the text to be displayed. * @param text the text to be displayed.
* @param modifier the [Modifier] to be applied to this text. * @param modifier the [Modifier] to be applied to this text.
* @param primaryFontSize whether the [fontSize] should be the same as the primary [Text], if you set this to true,
* the [fontSize] will be ignored, default is false.
* @param fontSize the font size of the text, see [TextStyle.fontSize].
* @param fontStyle the font style of the text, see [TextStyle.fontStyle]. * @param fontStyle the font style of the text, see [TextStyle.fontStyle].
* @param fontWeight the font weight of the text, see [TextStyle.fontWeight]. * @param fontWeight the font weight of the text, see [TextStyle.fontWeight].
* @param fontFamily the font family of the text, see [TextStyle.fontFamily]. * @param fontFamily the font family of the text, see [TextStyle.fontFamily].
@@ -212,6 +215,8 @@ fun Text(
fun SecondaryText( fun SecondaryText(
text: String, text: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
primaryFontSize: Boolean = false,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null, fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null, fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null, fontFamily: FontFamily? = null,
@@ -226,13 +231,11 @@ fun SecondaryText(
softWrap: Boolean = !singleLine || maxLines > 1, softWrap: Boolean = !singleLine || maxLines > 1,
onTextLayout: (TextLayoutResult) -> Unit = {} onTextLayout: (TextLayoutResult) -> Unit = {}
) { ) {
val textColor = LocalColors.current.textSecondary SecondaryText(
val textStyle = LocalTypography.current.secondary text = AnnotatedString(text),
Text(
text = text,
modifier = modifier, modifier = modifier,
color = textColor, primaryFontSize = primaryFontSize,
style = textStyle, fontSize = fontSize,
fontStyle = fontStyle, fontStyle = fontStyle,
fontWeight = fontWeight, fontWeight = fontWeight,
fontFamily = fontFamily, fontFamily = fontFamily,
@@ -257,6 +260,9 @@ fun SecondaryText(
* @see Text * @see Text
* @param text the text to be displayed. * @param text the text to be displayed.
* @param modifier the [Modifier] to be applied to this text. * @param modifier the [Modifier] to be applied to this text.
* @param primaryFontSize whether the [fontSize] should be the same as the primary [Text], if you set this to true,
* the [fontSize] will be ignored, default is false.
* @param fontSize the font size of the text, see [TextStyle.fontSize].
* @param fontStyle the font style of the text, see [TextStyle.fontStyle]. * @param fontStyle the font style of the text, see [TextStyle.fontStyle].
* @param fontWeight the font weight of the text, see [TextStyle.fontWeight]. * @param fontWeight the font weight of the text, see [TextStyle.fontWeight].
* @param fontFamily the font family of the text, see [TextStyle.fontFamily]. * @param fontFamily the font family of the text, see [TextStyle.fontFamily].
@@ -276,6 +282,8 @@ fun SecondaryText(
fun SecondaryText( fun SecondaryText(
text: AnnotatedString, text: AnnotatedString,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
primaryFontSize: Boolean = false,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null, fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null, fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null, fontFamily: FontFamily? = null,
@@ -293,11 +301,15 @@ fun SecondaryText(
) { ) {
val textColor = LocalColors.current.textSecondary val textColor = LocalColors.current.textSecondary
val textStyle = LocalTypography.current.secondary val textStyle = LocalTypography.current.secondary
val currentFontSize = if (primaryFontSize)
LocalTypography.current.primary.fontSize
else fontSize
Text( Text(
text = text, text = text,
modifier = modifier, modifier = modifier,
color = textColor, color = textColor,
style = textStyle, style = textStyle,
fontSize = currentFontSize,
fontStyle = fontStyle, fontStyle = fontStyle,
fontWeight = fontWeight, fontWeight = fontWeight,
fontFamily = fontFamily, fontFamily = fontFamily,