Skip to content

Commit

Permalink
Make all snackbars with actions persist until explicitly dismissed
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 598973358
  • Loading branch information
Janette James authored and material-automation committed Jan 16, 2024
1 parent 9da8583 commit 8a2b62a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
10 changes: 7 additions & 3 deletions components/Snackbar/src/MDCSnackbarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,15 @@ - (BOOL)isVoiceOverRunning {
}

- (BOOL)isSnackbarTransient:(MDCSnackbarMessageView *)snackbarView {
if ([self isVoiceOverRunning]) {
if (snackbarView.message.usesLegacyDismissalBehavior) {
if ([self isVoiceOverRunning]) {
return ![snackbarView shouldWaitForDismissalDuringVoiceover];
} else {
return YES;
}
} else {
return ![snackbarView shouldWaitForDismissalDuringVoiceover];
}

return YES;
}

#pragma mark - Overlay Activation
Expand Down
4 changes: 2 additions & 2 deletions components/Snackbar/src/MDCSnackbarMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ extern NSString *__nonnull const MDCSnackbarMessageBoldAttributeName;
Whether the Snackbar message is transient and automatically dismisses after the provided @c
duration time or is not transient and will not dismiss automatically.
@note: If VoiceOver is turned on, a snackbar will not automatically dismiss if the snackbar has an
action, regardless of this property.
@note: If the snackbar has an action, it will not dismiss automatically, regardless of the value of
this property, unless @c usesLegacyDismissalBehavior is enabled.
Defaults to YES.
*/
Expand Down
17 changes: 9 additions & 8 deletions components/Snackbar/tests/unit/MDCSnackbarMessageViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ - (void)testSnackbarAccessibiltyViewIsModalDefaultsToNoWithNoActions {
XCTAssertFalse(self.manager.internalManager.overlayView.accessibilityViewIsModal);
}

- (void)testWhenSnackbarAccessibiltyViewIsModalIsYesWithActions {
- (void)testSnackbarAccessibilityViewIsModalIsYesWithActions {
// Given
self.manager.internalManager.isVoiceOverRunningOverride = YES;
MDCSnackbarMessageAction *action = [[MDCSnackbarMessageAction alloc] init];
action.title = @"Tap Me";
self.message.action = action;
Expand All @@ -278,11 +277,9 @@ - (void)testWhenSnackbarAccessibiltyViewIsModalIsYesWithActions {
XCTAssertTrue(self.manager.internalManager.overlayView.accessibilityViewIsModal);
}

- (void)testWhenSnackbarAccessibiltyViewIsModalIsYesWithActionsAndWithoutVoiceOver {
- (void)testSnackbarAccessibiltyViewIsModalIsNoWithoutActions {
// Given
MDCSnackbarMessageAction *action = [[MDCSnackbarMessageAction alloc] init];
action.title = @"Tap Me";
self.message.action = action;
self.manager.internalManager.isVoiceOverRunningOverride = YES;
self.manager.shouldEnableAccessibilityViewIsModal = YES;

// When
Expand All @@ -297,9 +294,13 @@ - (void)testWhenSnackbarAccessibiltyViewIsModalIsYesWithActionsAndWithoutVoiceOv
XCTAssertFalse(self.manager.internalManager.overlayView.accessibilityViewIsModal);
}

- (void)testWhenSnackbarAccessibiltyViewIsModalIsYesWhenWithNoActions {
- (void)testSnackbarAccessibilityViewIsModalIsNoWithoutVoiceOverWithLegacyBehavior {
// Given
self.manager.internalManager.isVoiceOverRunningOverride = YES;
MDCSnackbarMessageAction *action = [[MDCSnackbarMessageAction alloc] init];
action.title = @"Tap Me";
self.message.action = action;
self.message.usesLegacyDismissalBehavior = YES;
self.manager.internalManager.isVoiceOverRunningOverride = NO;
self.manager.shouldEnableAccessibilityViewIsModal = YES;

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ - (void)setUp {

self.message = [[MDCSnackbarMessage alloc] init];
self.message.text = @"Snackbar Message";
MDCSnackbarMessageAction *action = [[MDCSnackbarMessageAction alloc] init];
action.title = @"Tap Me";
self.message.action = action;

self.fakeMessage = [[MDCFakeSnackbarMessage alloc] init];
self.fakeMessage.text = @"Fake Snackbar Message";
Expand Down

0 comments on commit 8a2b62a

Please sign in to comment.