Commit 3ac73739 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates showSnackbarWithMessage command

This new commands shows a Snackbar by creating the MDCSnackBarCommand in
the Coordinator, thus saving the caller to import Material components.

Bug: 1085419
Change-Id: Iee3d6c93f40b50558503d997d13c540d9e84c86d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333069
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795003}
parent aac032e9
......@@ -21,6 +21,17 @@
- (void)showSnackbarMessage:(MDCSnackbarMessage*)message
bottomOffset:(CGFloat)offset;
// Shows a snackbar displaying a message with |messageText| and a button with
// |buttonText| which triggers |messageAction| on tap. |completionAction| will
// be called when the snackbar finishes presenting, BOOL is YES if the dismissal
// was caused by a user action and NO if not. It will use the Bottom toolbar
// height as bottom offset. Use this method if displaying a Snackbar while the
// Web content is visible. If there's no bottom toolbar offset will be 0.
- (void)showSnackbarWithMessage:(NSString*)messageText
buttonText:(NSString*)buttonText
messageAction:(void (^)(void))messageAction
completionAction:(void (^)(BOOL))completionAction;
@end
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_SNACKBAR_COMMANDS_H_
......@@ -49,4 +49,25 @@
[[MDCSnackbarManager defaultManager] showMessage:message];
}
- (void)showSnackbarWithMessage:(NSString*)messageText
buttonText:(NSString*)buttonText
messageAction:(void (^)(void))messageAction
completionAction:(void (^)(BOOL))completionAction {
MDCSnackbarMessageAction* action = [[MDCSnackbarMessageAction alloc] init];
action.handler = messageAction;
action.title = buttonText;
action.accessibilityLabel = buttonText;
MDCSnackbarMessage* message =
[MDCSnackbarMessage messageWithText:messageText];
message.action = action;
message.completionHandler = completionAction;
NamedGuide* bottomToolbarGuide =
[NamedGuide guideWithName:kSecondaryToolbarGuide
view:self.baseViewController.view];
CGRect bottomToolbarFrame = bottomToolbarGuide.constrainedView.frame;
[self showSnackbarMessage:message
bottomOffset:bottomToolbarFrame.size.height];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment