mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 08:17:04 +05:30
common: use upstream ColorScheme#surfaceColorAtElevation
This commit is contained in:
parent
46ed4fd3f1
commit
492219e3a8
1 changed files with 4 additions and 17 deletions
|
@ -2,26 +2,13 @@ package dev.msfjarvis.claw.common.ui
|
|||
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.LocalAbsoluteTonalElevation
|
||||
import androidx.compose.material3.NavigationBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.compositeOver
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlin.math.ln
|
||||
|
||||
/**
|
||||
* Returns the [ColorScheme.surface] color with an alpha of the [ColorScheme.primary] color overlaid
|
||||
* on top of it. Computes the surface tonal color at different elevation levels e.g. surface1
|
||||
* through surface5.
|
||||
*
|
||||
* Stolen from AndroidX, keep in sync when upgrading Compose. This version is hard-coded to
|
||||
* replicate the logic used by the Material3 NavigationBar to determine its surface color.
|
||||
* https://github.com/androidx/androidx/blob/74d3510b608c3cc26b9cf9be8d15a6a6c26192c2/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/ColorScheme.kt#L453-L466
|
||||
*/
|
||||
@Composable
|
||||
fun ColorScheme.surfaceColorAtNavigationBarElevation(): Color {
|
||||
// Absolute tonal elevation + NavigationBarTokens.ContainerElevation
|
||||
val elevation = LocalAbsoluteTonalElevation.current + 3.0.dp
|
||||
if (elevation == 0.dp) return surface
|
||||
val alpha = ((4.5f * ln(elevation.value + 1)) + 2f) / 100f
|
||||
return primary.copy(alpha = alpha).compositeOver(surface)
|
||||
val elevation = LocalAbsoluteTonalElevation.current + NavigationBarDefaults.Elevation
|
||||
return surfaceColorAtElevation(elevation)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue