Created
July 29, 2022 07:21
-
-
Save skydoves/0e146baf44e17853001bc0a4b51ee8d1 to your computer and use it in GitHub Desktop.
whatsapp_background_composable
This file contains 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
@Immutable | |
data class BackgroundTheme( | |
val color: Color = Color.Unspecified, | |
val tonalElevation: Dp = Dp.Unspecified | |
) | |
val LocalBackgroundTheme = staticCompositionLocalOf { BackgroundTheme() } | |
@Composable | |
fun WhatsAppCloneBackground( | |
modifier: Modifier = Modifier, | |
content: @Composable () -> Unit | |
) { | |
val color = LocalBackgroundTheme.current.color | |
val tonalElevation = LocalBackgroundTheme.current.tonalElevation | |
Surface( | |
color = if (color == Color.Unspecified) Color.Transparent else color, | |
tonalElevation = if (tonalElevation == Dp.Unspecified) 0.dp else tonalElevation, | |
modifier = modifier.fillMaxSize() | |
) { | |
CompositionLocalProvider(LocalAbsoluteTonalElevation provides 0.dp) { | |
content() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment