MDCSnackbarManager

@interface MDCSnackbarManager : NSObject

Provides a means of displaying an unobtrusive message to the user.

The style and location of the message can vary depending on the configuration of the message to be shown. This class will queue repeated calls to @c showMessage: and show them at the appropriate time, once previous messages have been dismissed. This class is thread-safe as long as the messages given to MDCSnackbarManager are not mutated after being passed to @c showMessage:

Snackbars prefer an application’s main window is a subclass of @c MDCOverlayWindow. When a standard UIWindow is used an attempt is made to find the top-most view controller in the view hierarchy.

  • An instance of MDCSnackbarManager.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nonnull, class)
        MDCSnackbarManager *defaultManager;
  • Determines the Snackbar alignment to the screen.

    If called within an animation block, the change will be animated.

    Note

    This setting is only used when both the horizontal and vertical size classes of the presenting window are @c UIUserInterfaceSizeClassRegular. Otherwise @c MDCSnackbarAlignmentCenter will be used.

    Note

    The setter must be called from the main thread.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) MDCSnackbarAlignment alignment;
  • Shows @c message to the user, in a style consistent with the data contained in @c message.

    For messages with the same category, the firing of completion blocks has a guaranteed FIFO ordering. Ordering between completion blocks of different categories is not guaranteed. This method is safe to call from any thread.

    Declaration

    Objective-C

    - (void)showMessage:(nullable MDCSnackbarMessage *)message;
  • MDCSnackbarManager will display the messages in this view.

    Call this method to choose where in the view hierarchy Snackbar messages will be presented. It is only necessary to provide a host view if the default behavior is unable to find one on it’s own, most commonly when using MDCSnackbarManager inside an application extension. By default, if you use MDCSnackbarManager without calling @c setPresentationHostView, the manager will attempt to find a suitable view by stepping through the application windows. Explicitly providing a host view is only required if you need to manually manage the view hierarchy, or are inside a UIApplication extension.

    Note

    This method must be called from the main thread.

    Note

    Calling setPresentationHostView will not change the parent of the currently visible message.

    Declaration

    Objective-C

    - (void)setPresentationHostView:(nullable UIView *)hostView;
  • Checks if there is any message showing or queued. Does not consider suspended messages.

    Note

    This method must be called from the main thread.

    Declaration

    Objective-C

    - (BOOL)hasMessagesShowingOrQueued;
  • Bypasses showing the messages of the given @c category.

    Completion blocks are called, but the UI won’t show any queued messages and will dismiss any messages for the @c category. Calling this method with @c nil will dismiss all messages. This method is safe to call from any thread.

    Declaration

    Objective-C

    - (void)dismissAndCallCompletionBlocksWithCategory:
        (nullable NSString *)category;
  • How far from the bottom of the screen messages are displayed.

    If called within an animation block, the change will be animated.

    Note

    This method must be called from the main thread.

    Note

    This is meant for apps which have a navigation element such as a tab bar, which cannot move and should not be obscured.

    Declaration

    Objective-C

    - (void)setBottomOffset:(CGFloat)offset;
  • Suspends the display of all messages.

    Any messages currently on screen will remain on screen (and dismiss normally). During this time any incoming messages will be queued as normal.

    Declaration

    Objective-C

    - (nullable id<MDCSnackbarSuspensionToken>)suspendAllMessages;

    Return Value

    A token suitable for use in {@c +[MDCSnackbarManager resumeWithToken:]}. Letting this object deallocate is equivalent to calling {@c +[MDCSnackbarManager resumeMessagesWithToken:]}.

  • Suspends the display of all messages in a given category.

    Any messages currently on screen will remain on screen (and dismiss normally). During this time any incoming messages in this category will be queued as normal.

    Declaration

    Objective-C

    - (nullable id<MDCSnackbarSuspensionToken>)suspendMessagesWithCategory:
        (nullable NSString *)category;

    Parameters

    category

    The category for which message display will be suspended. Should not be nil.

    Return Value

    A token suitable for use in {@c +[MDCSnackbarManager resumeMessagesWithToken:]}. Letting this object dealloc is equivalent to calling {@c +[MDCSnackbarManager resumeMessagesWithToken:]}.

  • Resumes the display of messages once there are no outstanding suspension tokens.

    The provided token is invalidated and becomes useless.

    Declaration

    Objective-C

    - (void)resumeMessagesWithToken:(nullable id<MDCSnackbarSuspensionToken>)token;

    Parameters

    token

    The suspension token to invalidate.

  • The color for the background of the Snackbar message view.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable)
        UIColor *snackbarMessageViewBackgroundColor;
  • The color for the shadow color for the Snackbar message view.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable)
        UIColor *snackbarMessageViewShadowColor;
  • The color for the message text in the Snackbar message view.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *messageTextColor;
  • The font for the message text in the Snackbar message view.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIFont *messageFont;
  • The font for the button text in the Snackbar message view.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIFont *buttonFont;
  • If enabled, modifications of class styling properties will be applied immediately to the currently presented Snackbar.

    Default is set to NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        BOOL shouldApplyStyleChangesToVisibleSnackbars;
  • Returns the button title color for a particular control state.

    Declaration

    Objective-C

    - (nullable UIColor *)buttonTitleColorForState:(UIControlState)state;

    Parameters

    state

    The control state.

    Return Value

    The button title color for the requested state.

  • Sets the button title color for a particular control state.

    Declaration

    Objective-C

    - (void)setButtonTitleColor:(nullable UIColor *)titleColor
                       forState:(UIControlState)state;

    Parameters

    titleColor

    The title color.

    state

    The control state.

  • Indicates whether the Snackbar should automatically update its font when the device’s UIContentSizeCategory is changed.

    This property is modeled after the adjustsFontForContentSizeCategory property in the UIContentSizeCategoryAdjusting protocol added by Apple in iOS 10.0.

    If set to YES, this button will base its message font on MDCFontTextStyleBody2 and its button font on MDCFontTextStyleButton.

    Default is set to NO.

    Declaration

    Objective-C

    @property (setter=mdc_setAdjustsFontForContentSizeCategory:, assign, readwrite,
              nonatomic) BOOL mdc_adjustsFontForContentSizeCategory;
  • If enabled, accessibilityViewIsModal will be enabled for all non-transient snackbar views by default. If accessibilityViewIsModal needs to be set for specific snackbar views, -willPresentSnackbarWithMessageView: in MDCSnackbarManagerDelegate can be used to access snackbar view and set the accessibilityViewIsModal value.

    Default is set to NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        BOOL shouldEnableAccessibilityViewIsModal;
  • The delegate for MDCSnackbarManager through which it may inform of snackbar presentation updates.

    Declaration

    Objective-C

    @property (readwrite, nonatomic, nullable) id<MDCSnackbarManagerDelegate>
        delegate;