Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ fun SnackBarStackDemoLayout(context: V2StackableSnackbarActivity) {
}
}
),
getTrailingIconBasedOnOverflow = {
null
},
onTitleOverflowChange = { },
onActionTextClicked = {
stackState.toggleExpandedState()
},
Expand Down Expand Up @@ -175,9 +173,7 @@ fun SnackBarStackDemoLayout(context: V2StackableSnackbarActivity) {
}
}
),
getTrailingIconBasedOnOverflow = {
null
},
onTitleOverflowChange = { },
onActionTextClicked = {
stackState.toggleExpandedState()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private val DEFAULT_SNACKBAR_TOKENS = StackableSnackBarTokens()
* @property snackBarToken The tokens for customizing the snackbar's appearance.
* @property onActionTextClicked The callback to be invoked when the action button is clicked.
* @property enableSwipeToDismiss If `true`, swiping the snackbar item horizontally will dismiss it.
* @property getTrailingIconBasedOnOverflow The callback to determine the trailing icon based on whether the text has overflow. It receives a boolean indicating if there is an overflow and returns a FluentIcon to be used as the trailing icon.
* @property onTitleOverflowChange The callback to determine on whether the text(title) has overflown. It receives a boolean indicating if there is an overflow.
*/
@Stable
data class SnackBarItemModel(
Expand All @@ -150,7 +150,7 @@ data class SnackBarItemModel(
val snackBarToken: StackableSnackBarTokens = DEFAULT_SNACKBAR_TOKENS,
val onActionTextClicked: () -> Unit = {},
val enableSwipeToDismiss: Boolean = true,
val getTrailingIconBasedOnOverflow: (Boolean) -> FluentIcon? = { _ -> trailingIcon }
val onTitleOverflowChange: ((Boolean) -> Unit)? = null
)

internal data class SnackbarItemInternal(
Expand Down Expand Up @@ -716,7 +716,6 @@ private fun SnackBarStackItem(
) {

var hasTextOverflow by remember { mutableStateOf(false) }
val trailingIcon by remember { derivedStateOf { model.getTrailingIconBasedOnOverflow(hasTextOverflow) ?: model.trailingIcon } }
if (model.leadingIcon != null && model.leadingIcon.isIconAvailable()) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -758,6 +757,7 @@ private fun SnackBarStackItem(
onTextLayout = { textLayout ->
if (hasTextOverflow != textLayout.hasVisualOverflow) {
hasTextOverflow = textLayout.hasVisualOverflow
model.onTitleOverflowChange?.invoke(hasTextOverflow)
}
}
)
Expand Down Expand Up @@ -799,7 +799,7 @@ private fun SnackBarStackItem(
)
}

trailingIcon?.let { icon ->
model.trailingIcon?.let { icon ->
if (icon.isIconAvailable()) {
Box(
modifier = Modifier
Expand Down
Loading