Last active
March 12, 2021 21:30
-
-
Save pablobaldez/5438489cf49ae7a976c3b8f3281a29f7 to your computer and use it in GitHub Desktop.
TwoLine with text style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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