Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Dropdown wrong default color #40

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified cascade-compose/src/androidTest/screenshots/canary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cascade-compose/src/androidTest/screenshots/zero_sized_anchor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions cascade-compose/src/main/java/me/saket/cascade/Cascade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MenuDefaults
import androidx.compose.material3.MenuItemColors
import androidx.compose.material3.Surface
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
Expand Down Expand Up @@ -118,6 +119,7 @@ fun CascadeDropdownMenu(
offset: DpOffset = DpOffset.Zero,
fixedWidth: Dp = 196.dp,
shadowElevation: Dp = 3.dp,
tonalElevation: Dp = 3.dp,
Copy link
Owner

@saket saket Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need your popups to have a different shadow and tonal elevations?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't, but others might and this matches the Compose API as it gives both options

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

properties: PopupProperties = PopupProperties(focusable = true),
state: CascadeState = rememberCascadeState(),
content: @Composable CascadeColumnScope.() -> Unit
Expand Down Expand Up @@ -177,6 +179,7 @@ fun CascadeDropdownMenu(
expandedStates = expandedStates,
transformOriginState = transformOriginState,
shadowElevation = shadowElevation,
tonalElevation = tonalElevation,
content = content
)
}
Expand All @@ -189,6 +192,7 @@ internal fun PopupContent(
modifier: Modifier = Modifier,
state: CascadeState,
fixedWidth: Dp,
tonalElevation: Dp,
shadowElevation: Dp,
expandedStates: MutableTransitionState<Boolean>,
transformOriginState: MutableState<TransformOrigin>,
Expand All @@ -206,7 +210,8 @@ internal fun PopupContent(
.requiredWidth(fixedWidth)
.then(modifier),
state = state,
tonalElevation = shadowElevation,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation,
content = content
)
}
Expand All @@ -217,6 +222,7 @@ private fun CascadeDropdownMenuContent(
state: CascadeState,
modifier: Modifier = Modifier,
tonalElevation: Dp,
shadowElevation: Dp,
content: @Composable CascadeColumnScope.() -> Unit,
) {
DisposableEffect(Unit) {
Expand All @@ -229,6 +235,7 @@ private fun CascadeDropdownMenuContent(
shape = MaterialTheme.shapes.extraSmall,
color = MaterialTheme.colorScheme.surface,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation,
) {
val isTransitionRunning = remember { MutableStateFlow(false) }
val backStackSnapshot by remember {
Expand All @@ -252,7 +259,7 @@ private fun CascadeDropdownMenuContent(
Modifier
// Provide a solid background color to prevent the
// content of sub-menus from leaking into each other.
.background(MaterialTheme.colorScheme.surface)
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(tonalElevation))
.verticalScroll(rememberScrollState())
) {
val currentContent = snapshot.topMostEntry?.childrenContent ?: content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ class CascadeDropdownMenuTest(
PopupContent(
state = state,
fixedWidth = 196.dp, // Same as used by CascadeDropdownMenu().
shadowElevation = 8.dp,
shadowElevation = 0.dp,
expandedStates = MutableTransitionState(true),
transformOriginState = remember { mutableStateOf(TransformOrigin.Center) },
content = content,
tonalElevation = 0.dp,
)
}
}
Expand Down