saket / cascade

Nested popup menus with smooth height animations for Android
https://saket.github.io/cascade
Apache License 2.0
2.02k stars 67 forks source link

Interested in adding a centered animated popup menu? #42

Closed MV-GH closed 11 months ago

MV-GH commented 1 year ago

I made centered popup menu variation of of the CascadeDropdownMenu. Are you interested in having this added to this library?

https://github.com/saket/cascade/assets/67873169/c16b74e5-99c7-4a9a-a4ed-7a13e1f04ce8

Source Code ```kt @Composable fun CascadeCenteredDropdownMenu( expanded: Boolean, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, fixedWidth: Dp = LocalConfiguration.current.screenWidthDp.dp * POPUP_MENU_WIDTH_RATIO, shadowElevation: Dp = 3.dp, properties: PopupProperties = PopupProperties(focusable = true), state: CascadeState = rememberCascadeState(), content: @Composable CascadeColumnScope.() -> Unit, ) { val expandedStates = remember { MutableTransitionState(false) } expandedStates.targetState = expanded if (expandedStates.currentState || expandedStates.targetState) { val transformOriginState = remember { mutableStateOf(TransformOrigin.Center) } // A full sized popup is shown so that content can render fake shadows // that do not suffer from https://issuetracker.google.com/issues/236109671. Popup( alignment = Alignment.Center, onDismissRequest = onDismissRequest, properties = properties.copy(usePlatformDefaultWidth = false), ) { Box( Modifier .fillMaxSize() .then(properties.dismissOnClickOutside) { clickableWithoutRipple(onClick = onDismissRequest) }, Alignment.Center, ) { PopupContent( modifier = Modifier // Prevent clicks from leaking behind. Otherwise, they'll get picked up as outside // clicks to dismiss the popup. This must be set _before_ the downstream modifiers to // avoid overriding any clickable modifiers registered by the developer. .clickableWithoutRipple {} .padding(vertical = LARGE_PADDING) .then(modifier), state = state, fixedWidth = fixedWidth, expandedStates = expandedStates, transformOriginState = transformOriginState, shadowElevation = shadowElevation, tonalElevation = 3.dp, content = content, ) } } } } ```

If not, could you allow making PopupContent not internal so I can depend on the upstream?

@saket

saket commented 11 months ago

Thanks for asking! I don't think I want to offer two variants for keeping the library simple.

If not, could you allow making PopupContent not internal so I can depend on the upstream?

You still can!

@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")

import me.saket.cascade.PopupContent as CascadePopupContent
MV-GH commented 3 months ago

That workaround may not work for long. K2 compiler gives warnings for it

w: file://app/src/main/java/com/jerboa/util/cascade/CustomCascadeDropdown.kt:3:36 This code uses error suppression for 'INVISIBLE_REFERENCE'. While it might compile and work, the compiler behavior is UNSPECIFIED and WON'T BE PRESERVED. Please report your use case to the Kotlin issue tracker instead: https://kotl.in/issue