Material-components-ios: Snackbar - Duration

Created on 23 Jun 2017  路  4Comments  路  Source: material-components/material-components-ios

Hi.
i using Swift 3. And snackbar duration max default 10 sec. How can i change MDCSnackbarMessageDurationMax value ?
And It must be the feature of disappearing only in the tapped snackbar.

Feature request Question

All 4 comments

Hi @ulaserdegor. The Snackbar is intended only for transient messages as a result of user actions, so I don't think it's a good fit for a persistent message. Since it obscures the content below it, a persistent Snackbar shouldn't persist for very long (hence the maximum duration and no stacking).

Have looked at the AppBar? It supports expanding to an optional bottomBar in the headerStackView property.

Hi @ulaserdegor. I'm closing this with the hope that @romoore offered some insight on the issue. If you still have questions, please re-open.

This is a parity issue with Android. Android supports INDEFINITE snackbars, iOS doesn't, which means there are use cases that can be implemented in one platform but not the other.

Also, IMO, the material design guideline is just that... a guideline. It shouldn't dictate how you use the components. If my designers want an indefinite snackbar, that should be up to them.

Also, this could present a problem for users taking advantage of accessibility features. depending on how long the snackbar text and actions take to announce, the bar could close before the user has a chance to interact with it.

This is not a good solution, but better than nothing.

class PseudoInfiniteMDCSnackbarMessage: MDCSnackbarMessage {
    override init() {
        super.init()
    }

    init(text: String) {
        super.init()
        self.text = text
    }

    public var isNeedToDismiss = false

    public var customDuration: TimeInterval = 9999999
    override var duration: TimeInterval {
        get {
            return isNeedToDismiss ? 0 : customDuration
        }
        set { }
    }

    public var customCategory: String? = "infinite"
    override var category: String? {
        get {
            return customCategory
        }
        set { }
    }
}

There is a bug. It will not dismiss if you will not set property isNeedToDismiss to true manually. That's why you'll probably need to save the instance of your message.

For force dismissing you should use something like this:

messageInfinite.isNeedToDismiss = true
MDCSnackbarManager.dismissAndCallCompletionBlocks(withCategory: "infinite")

for close of it.

May be, somebody has better solution without manual editing of the library.

Was this page helpful?
0 / 5 - 0 ratings