Material-components-ios: is there a way to know when snackbar/toast is dismissed (callback)?

Created on 13 Apr 2017  路  5Comments  路  Source: material-components/material-components-ios

Overview

Looking at the the android API, there is addCallback() to know when the toast message is dismissed. Is there a similar API hook for the pod? I looked through the source and didn't see anything obvious.

thanks

[Snackbar] Question

Most helpful comment

In SnackbarSimpleExample, you can assign the completion handler block directly to the message. Be careful of introducing retain cycles if you retain the snackbar message!

- (void)showSimpleSnackbar:(id)sender {
  MDCSnackbarMessage *message = [[MDCSnackbarMessage alloc] init];
  message.text = @"Snackbar Message";
  // Added this assignment to demonstrate completion blocks.
  message.completionHandler = ^(BOOL userInitiated) {
    NSLog(@"Hello, world!");
  };
  [MDCSnackbarManager showMessage:message];
}

All 5 comments

Yes! You can use the completion handler.

Sorry for commenting on this closed issue but how would I use that exactly? Is there a example somewhere?

In SnackbarSimpleExample, you can assign the completion handler block directly to the message. Be careful of introducing retain cycles if you retain the snackbar message!

- (void)showSimpleSnackbar:(id)sender {
  MDCSnackbarMessage *message = [[MDCSnackbarMessage alloc] init];
  message.text = @"Snackbar Message";
  // Added this assignment to demonstrate completion blocks.
  message.completionHandler = ^(BOOL userInitiated) {
    NSLog(@"Hello, world!");
  };
  [MDCSnackbarManager showMessage:message];
}

Wow! Thank you for the this quick and informative response. Great work.

You're welcome. Thanks for checking out MDC-iOS!

Was this page helpful?
0 / 5 - 0 ratings