Skip to content

Instantly share code, notes, and snippets.

@pablobaldez
Last active March 12, 2021 21:30
Show Gist options
  • Save pablobaldez/5438489cf49ae7a976c3b8f3281a29f7 to your computer and use it in GitHub Desktop.
Save pablobaldez/5438489cf49ae7a976c3b8f3281a29f7 to your computer and use it in GitHub Desktop.
TwoLine with text style
@Composable
fun TwoLine(
modifier: Modifier = Modifier,
secondary: @Composable () -> Unit,
primary: @Composable () -> Unit,
) {
val styledPrimary = applyStyle(
textStyle = MaterialTheme.typography.subtitle1,
alpha = ContentAlpha.high,
content = primary
)
val styledSecondary = applyStyle(
textStyle = MaterialTheme.typography.body2,
alpha = ContentAlpha.medium,
content = secondary
)
Column(modifier = modifier) {
styledPrimary?.invoke()
styledSecondary?.invoke()
}
}
fun applyStyle(
textStyle: TextStyle,
alpha: Float,
content: @Composable (() -> Unit)?
): @Composable (() -> Unit)? {
if (content == null) return null
return {
Providers(AmbientContentAlpha provides alpha) {
ProvideTextStyle(textStyle, content)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment