class MaskEdgeDecorator( val edgeRadius: Dp, ) : NavEntryDecorator( decorate = { entry -> if (entry.metadata[IGNORE_MASK] == true) entry.Content() else { val animatedContentScope = LocalNavAnimatedContentScope.current val clipProgress by with(animatedContentScope) { val parent = transition.parentTransition val current = parent?.currentState as? Scene<*>? val next = parent?.targetState as? Scene<*>? val currentlyPopped = current?.entries?.lastOrNull()?.contentKey == entry.contentKey && (next == null || current.previousEntries.size > next.previousEntries.size) if (!currentlyPopped) mutableFloatStateOf(0F) else transition.animateFloat { when (it) { EnterExitState.PreEnter, EnterExitState.Visible -> 0F EnterExitState.PostExit -> 1F } } } val systemRadiusShape = when (animatedContentScope.transition.isRunning) { true -> WindowInsets.cornerRadius .lerp(RoundedCornerShape(edgeRadius), clipProgress) as RoundedCornerShape false -> RoundedCornerShape(0) } Box( Modifier.clip(systemRadiusShape), content = { entry.Content() }, ) } }, ) @Composable fun rememberMaskEdgeDecorator(edgeRadius: Dp) = remember(edgeRadius) { MaskEdgeDecorator(edgeRadius) } fun NavDisplay.ignoreMask() = mapOf(IGNORE_MASK to true) const val IGNORE_MASK = "ignoreMask"