@@ -98,6 +98,12 @@ private object SnackBarTestTags {
9898 const val SNACK_BAR_ACTION_BUTTON = " snack_bar_action_button"
9999}
100100
101+ private object SnackBarLabels {
102+ const val STACK_HEIGHT_ANIMATION = " StackHeightAnimation"
103+ const val WIDTH_SCALE_ANIMATION = " WidthScaleAnimation"
104+ const val SCRIM_COLOR_ANIMATION = " ScrimColorAnimation"
105+ }
106+
101107/* *
102108 * Enum class to define the visibility state of a snackbar item within the stack.
103109 */
@@ -126,6 +132,7 @@ private val DEFAULT_SNACKBAR_TOKENS = StackableSnackBarTokens()
126132 * @property actionText Optional text for the action button. If null, no action button is shown.
127133 * @property snackBarToken The tokens for customizing the snackbar's appearance.
128134 * @property onActionTextClicked The callback to be invoked when the action button is clicked.
135+ * @property enableSwipeToDismiss If `true`, swiping the snackbar item horizontally will dismiss it.
129136 */
130137@Stable
131138data class SnackBarItemModel (
@@ -137,7 +144,8 @@ data class SnackBarItemModel(
137144 val subTitle : String? = null ,
138145 val actionText : String? = null ,
139146 val snackBarToken : StackableSnackBarTokens = DEFAULT_SNACKBAR_TOKENS ,
140- val onActionTextClicked : () -> Unit = {}
147+ val onActionTextClicked : () -> Unit = {},
148+ val enableSwipeToDismiss : Boolean = true
141149)
142150
143151internal data class SnackbarItemInternal (
@@ -423,13 +431,11 @@ data class SnackBarStackConfig(
423431 *
424432 * @param state The state object that manages the snackbar stack.
425433 * @param snackBarStackConfig The configuration for the stack's appearance and behavior.
426- * @param enableSwipeToDismiss If `true`, the top visible snackbar can be swiped to dismiss it.
427434 */
428435@Composable
429436fun SnackBarStack (
430437 state : SnackBarStackState ,
431- snackBarStackConfig : SnackBarStackConfig = SnackBarStackConfig (),
432- enableSwipeToDismiss : Boolean = true,
438+ snackBarStackConfig : SnackBarStackConfig = SnackBarStackConfig ()
433439) {
434440 val localDensity = LocalDensity .current
435441
@@ -444,7 +450,7 @@ fun SnackBarStack(
444450 val animatedStackHeight by animateDpAsState(
445451 targetValue = targetHeight,
446452 animationSpec = tween(durationMillis = ANIMATION_DURATION_MS , easing = FastOutSlowInEasing ),
447- label = " StackHeightAnimation "
453+ label = SnackBarLabels . STACK_HEIGHT_ANIMATION
448454 )
449455
450456 val screenWidth = LocalConfiguration .current.screenWidthDp.dp
@@ -481,7 +487,6 @@ fun SnackBarStack(
481487 state.showLastHidden()
482488 },
483489 snackBarStackConfig = snackBarStackConfig,
484- enableSwipeToDismiss = enableSwipeToDismiss,
485490 screenWidthPx = screenWidthPx
486491 )
487492 }
@@ -499,7 +504,6 @@ fun SnackBarStack(
499504 * @param trueIndex The actual index of the snackbar in the full list.
500505 * @param onSwipedAway A callback to be invoked when the snackbar is swiped off-screen.
501506 * @param snackBarStackConfig The configuration for the stack's appearance.
502- * @param enableSwipeToDismiss If `true`, swiping the snackbar horizontally will dismiss it.
503507 * @param screenWidthPx The width of the screen in pixels, used for swipe animation.
504508 */
505509@Composable
@@ -509,7 +513,6 @@ private fun SnackBarStackItem(
509513 trueIndex : Int ,
510514 onSwipedAway : (String ) -> Unit ,
511515 snackBarStackConfig : SnackBarStackConfig ,
512- enableSwipeToDismiss : Boolean = true,
513516 screenWidthPx : Float
514517) {
515518 val modelWrapper = state.snapshotStateList[trueIndex]
@@ -561,7 +564,7 @@ private fun SnackBarStackItem(
561564 val animatedWidthScale = animateFloatAsState(
562565 targetValue = targetWidthScale,
563566 animationSpec = tween(durationMillis = ANIMATION_DURATION_MS , easing = FastOutSlowInEasing ),
564- label = " WidthScaleAnimation "
567+ label = SnackBarLabels . WIDTH_SCALE_ANIMATION
565568 )
566569
567570 // Opacity Animation: Related to Entry/Exit Fade Animations
@@ -644,7 +647,7 @@ private fun SnackBarStackItem(
644647 )
645648 .wrapContentHeight()
646649 .then(
647- if (enableSwipeToDismiss && (isTop || state.expanded)) Modifier .pointerInput(model.id) {
650+ if (model. enableSwipeToDismiss && (isTop || state.expanded)) Modifier .pointerInput(model.id) {
648651 detectHorizontalDragGestures(
649652 onDragStart = {},
650653 onDragEnd = {
@@ -835,7 +838,7 @@ fun Scrim(
835838 val scrimColor by animateColorAsState(
836839 targetValue = if (isActivated) activatedColor else Color .Transparent ,
837840 animationSpec = tween(durationMillis = ANIMATION_DURATION_MS ),
838- label = " ScrimColorAnimation "
841+ label = SnackBarLabels . SCRIM_COLOR_ANIMATION
839842 )
840843
841844 if (scrimColor.alpha > 0f ) {
0 commit comments