Skip to content

Commit

Permalink
[MDCSnackbar] Add snackbarIsPresenting to MDCSnackbarManagerDelegate.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 312316674
  • Loading branch information
Nobody authored and material-automation committed May 19, 2020
1 parent dfd5109 commit 0fcf353
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components/Snackbar/src/MDCSnackbarManager.m
Expand Up @@ -270,6 +270,10 @@ - (void)displaySnackbarViewForMessage:(MDCSnackbarMessage *)message {
});
}
}];

if ([self.delegate respondsToSelector:@selector(isPresentingSnackbarWithMessageView:)]) {
[self.delegate isPresentingSnackbarWithMessageView:snackbarView];
}
}

- (MDCSnackbarOverlayView *)overlayView {
Expand Down
8 changes: 8 additions & 0 deletions components/Snackbar/src/MDCSnackbarManagerDelegate.h
Expand Up @@ -36,4 +36,12 @@
*/
- (void)snackbarDidDisappear;

/**
This method is called after the snackbar begins presenting (and is laid out),
but before the animiation is finished.
@param messageView The messageView of the snackbar that was just presented.
*/
- (void)isPresentingSnackbarWithMessageView:(nullable MDCSnackbarMessageView *)messageView;

@end
12 changes: 11 additions & 1 deletion components/Snackbar/tests/unit/MDCSnackbarMessageViewTests.m
Expand Up @@ -624,10 +624,20 @@ - (void)testNotDismissedOnScreenTap {

// Then
[NSThread sleepForTimeInterval:0.5];
// Unfortunately, there is no way to to assert an expectation has *not* fired after a time
// Unfortunately, there is no way to to assert an expectation has *not* fired after a time
// interval. Instead we rely on 'internalManager.currentSnackbar' to be nil iff the snackbar is
// dismissed.
XCTAssertNotNil(self.manager.internalManager.currentSnackbar);
}

- (void)testsnackbarIsPresentingDelegateCalled {
// Given
self.delegate.willPresentExpectation = [self expectationWithDescription:@"willPresent"];
self.delegate.isPresentingExpectation = [self expectationWithDescription:@"isPresenting"];
// When
[self.manager showMessage:self.message];
// Then
[self waitForExpectationsWithTimeout:0.2 handler:nil];
}

@end
Expand Up @@ -22,7 +22,6 @@
@property(nonatomic, assign) BOOL shouldSetSnackbarViewAccessibilityViewIsModal;
@property(nonatomic, assign) XCTestExpectation *disappearExpectation;
@property(nonatomic, assign) XCTestExpectation *willPresentExpectation;

- (void)willPresentSnackbarWithMessageView:(MDCSnackbarMessageView *)messageView;
@property(nonatomic, assign) XCTestExpectation *isPresentingExpectation;

@end
Expand Up @@ -28,4 +28,8 @@ - (void)snackbarDidDisappear {
[self.disappearExpectation fulfill];
}

- (void)isPresentingSnackbarWithMessageView:(nullable MDCSnackbarMessageView *)messageView {
[self.isPresentingExpectation fulfill];
}

@end

0 comments on commit 0fcf353

Please sign in to comment.