From 01b52bc479484d24dbeb0dd1b8bec06df18ee3b4 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 3 Aug 2020 13:41:37 -0400 Subject: [PATCH 1/4] 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 From b1d0aa55c4a9d388f24f06c10c5f987e1c09577b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 3 Aug 2020 16:42:13 -0400 Subject: [PATCH 2/4] adjust other config endpoints. --- MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index 3c75445b..8994b340 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -61,6 +61,13 @@ } } +- (void)amendAccesibilityLabel { + NSString *amendment = [MVMCoreUIUtility hardcodedStringWithKey:@"top_alert_notification"]; + if (![self.buttonView.label.accessibilityLabel hasPrefix:amendment]) { + self.buttonView.label.accessibilityLabel = [NSString stringWithFormat:@"%@ - %@", amendment, self.buttonView.label.accessibilityLabel]; + } +} + #pragma mark - Setup View - (void)updateView:(CGFloat)size { @@ -163,12 +170,13 @@ - (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]; self.buttonView = topAlertWithButton; + [self amendAccesibilityLabel]; + self.topConstraint = [NSLayoutConstraint constraintWithItem:topAlertWithButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.shortView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; [NSLayoutConstraint constraintPinSubview:topAlertWithButton pinTop:NO topConstant:0 pinBottom:YES bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0]; } @@ -209,6 +217,7 @@ [MVMCoreDispatchUtility performBlockOnMainThread:^{ [self setTopMessage:topMessage]; [self.buttonView setupWithMessage:message subMessage:subMessage color:contentColor actionMap:actionMap additionalData:additionalData]; + [self amendAccesibilityLabel]; }]; } @@ -216,6 +225,7 @@ [MVMCoreDispatchUtility performBlockOnMainThread:^{ [self setTopMessage:topMessage]; [self.buttonView setupWithMessage:message subMessage:subMessage color:contentColor buttonTitle:buttonTitle userActionHandler:userActionHandler]; + [self amendAccesibilityLabel]; }]; } From 4cc2a1cda0326cfe2fcff309d750dc82dc9e5693 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Thu, 6 Aug 2020 18:25:12 -0400 Subject: [PATCH 3/4] shim accessibility for testers. --- MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index 8994b340..a00603da 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -63,8 +63,13 @@ - (void)amendAccesibilityLabel { NSString *amendment = [MVMCoreUIUtility hardcodedStringWithKey:@"top_alert_notification"]; - if (![self.buttonView.label.accessibilityLabel hasPrefix:amendment]) { - self.buttonView.label.accessibilityLabel = [NSString stringWithFormat:@"%@ - %@", amendment, self.buttonView.label.accessibilityLabel]; + NSString *accessibilityLabel = self.buttonView.label.accessibilityLabel; + if (!accessibilityLabel) { + // The accessibility label is nil when in non-voice over mode. Therefore assign the label text for the voice over is turned on mid-session (i.e. testers 🤦). + accessibilityLabel = self.buttonView.label.text; + } + if (accessibilityLabel && ![accessibilityLabel hasPrefix:amendment]) { + self.buttonView.label.accessibilityLabel = [NSString stringWithFormat:@"%@ - %@", amendment, accessibilityLabel]; } } From d3227649875f4ff43d71e37603cbc81fe4545297 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 7 Aug 2020 11:35:15 -0400 Subject: [PATCH 4/4] code review enhancement --- MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index a00603da..ad9f5e3d 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -414,14 +414,7 @@ if (![focusedElement isKindOfClass:[UIView class]]) { return NO; } - UIView *focusedView = focusedElement; - while (focusedView != nil) { - if (focusedView == self) { - return YES; - } - focusedView = [focusedView superview]; - } - return NO; + return [(UIView *)focusedElement isDescendantOfView:self]; } - (void)accessibilityFocusChanged:(NSNotification *)notification {