diff --git a/components/Snackbar/src/MDCSnackbarMessage.m b/components/Snackbar/src/MDCSnackbarMessage.m index b500b70ea77..8958440038d 100644 --- a/components/Snackbar/src/MDCSnackbarMessage.m +++ b/components/Snackbar/src/MDCSnackbarMessage.m @@ -13,8 +13,9 @@ // limitations under the License. #import "MDCSnackbarMessage.h" -#import "MDCSnackbarMessageView.h" #import "private/MDCSnackbarMessageInternal.h" +#import "MDCAvailability.h" +#import "MDCSnackbarMessageView.h" static const NSTimeInterval kDefaultDuration = 4; @@ -108,7 +109,17 @@ - (NSString *)description { #pragma mark Text - (void)setText:(NSString *)text { - self.attributedText = [[NSAttributedString alloc] initWithString:[text copy]]; + NSDictionary *attributes = @{}; + + // TODO(b/298435271): Remove the #if check below once all users are building with Xcode 15. +#if MDC_AVAILABLE_SDK_IOS(17_0) + if (@available(iOS 17.0, *)) { + // Default to low-priority announcements. + attributes = @{UIAccessibilitySpeechAttributeAnnouncementPriority : UIAccessibilityPriorityLow}; + } +#endif + self.attributedText = [[NSAttributedString alloc] initWithString:[text copy] + attributes:attributes]; } - (NSString *)text { @@ -130,8 +141,18 @@ - (void)setAccessibilityLabel:(NSString *)accessibilityLabel { if (accessibilityLabel == nil) { self.attributedAccessibilityLabel = nil; } else { + NSDictionary *attributes = @{}; + + // TODO(b/298435271): Remove the #if check below once all users are building with Xcode 15. +#if MDC_AVAILABLE_SDK_IOS(17_0) + if (@available(iOS 17.0, *)) { + // Default to low-priority announcements. + attributes = + @{UIAccessibilitySpeechAttributeAnnouncementPriority : UIAccessibilityPriorityLow}; + } +#endif self.attributedAccessibilityLabel = - [[NSAttributedString alloc] initWithString:[accessibilityLabel copy]]; + [[NSAttributedString alloc] initWithString:[accessibilityLabel copy] attributes:attributes]; } }