From 01b52bc479484d24dbeb0dd1b8bec06df18ee3b4 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 3 Aug 2020 13:41:37 -0400 Subject: [PATCH] prevent expandable alert collapse when accessibilty focused. top alert notification callout fix. --- .../MVMCoreUITopAlertExpandableView.m | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index ed9f5271..3c75445b 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -74,6 +74,7 @@ self.translatesAutoresizingMaskIntoConstraints = NO; self.clipsToBounds = YES; self.expanded = NO; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessibilityFocusChanged:) name:UIAccessibilityElementFocusedNotification object:nil]; } return self; } @@ -162,6 +163,7 @@ - (void)setupTopAlertWithButton:(MVMCoreUITopAlertMainView *)topAlertWithButton { topAlertWithButton.label.alpha = 0; + topAlertWithButton.label.accessibilityLabel = [NSString stringWithFormat:@"%@ - %@", [MVMCoreUIUtility hardcodedStringWithKey:@"top_alert_notification"], topAlertWithButton.label.accessibilityLabel]; topAlertWithButton.button.alpha = 0; topAlertWithButton.backgroundColor = [UIColor clearColor]; [self insertSubview:topAlertWithButton belowSubview:self.shortView]; @@ -304,7 +306,6 @@ //accessibility - added to make only top alert label and close button accessible. Posted notification when top alert is displayed weakSelf.accessibilityElements = @[weakSelf.buttonView]; weakSelf.shortView.isAccessibilityElement = NO; - weakSelf.buttonView.label.accessibilityLabel = [NSString stringWithFormat:@"%@ - %@", [MVMCoreUIUtility hardcodedStringWithKey:@"top_alert_notification"],weakSelf.buttonView.label.accessibilityLabel]; void(^completion)(void) = ^(void) { UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, weakSelf.buttonView.label); @@ -346,7 +347,7 @@ } dispatch_time_t dispatchTime = dispatch_time(DISPATCH_TIME_NOW, dismissTime * NSEC_PER_SEC); dispatch_after(dispatchTime, dispatch_get_main_queue(), ^(void){ - if (weakSelf && weakSelf.expanded && weakSelf.collapseAutomaticallyAfterExpanded) { + if (weakSelf && weakSelf.expanded && weakSelf.collapseAutomaticallyAfterExpanded && ![self containsAccessiblityFocus]) { [weakSelf collapse]; } }); @@ -390,4 +391,28 @@ } } +- (BOOL)containsAccessiblityFocus { + if (!UIAccessibilityIsVoiceOverRunning()) { + return NO; + } + id focusedElement = UIAccessibilityFocusedElement(UIAccessibilityNotificationVoiceOverIdentifier); + if (![focusedElement isKindOfClass:[UIView class]]) { + return NO; + } + UIView *focusedView = focusedElement; + while (focusedView != nil) { + if (focusedView == self) { + return YES; + } + focusedView = [focusedView superview]; + } + return NO; +} + +- (void)accessibilityFocusChanged:(NSNotification *)notification { + if (![self containsAccessiblityFocus]) { + [self collapse]; + } +} + @end