Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Corrected annotation view accessibility frame
Browse files Browse the repository at this point in the history
Corrected the accessibility frames of annotation views to match the views’ bounds instead of the bounds of the default annotation image (which could be empty if no default GL point annotation has been added).

Fixes #5038.
  • Loading branch information
1ec5 committed Jun 3, 2016
1 parent ab5e8fb commit 1fdda91
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) {
/// Distance from the callout’s anchor point to the annotation it points to.
const CGFloat MGLAnnotationImagePaddingForCallout = 1;

/// Minimum size of an annotation’s accessibility element.
const CGSize MGLAnnotationAccessibilityElementMinimumSize = CGSizeMake(10, 10);

/// Unique identifier representing a single annotation in mbgl.
typedef uint32_t MGLAnnotationTag;

Expand Down Expand Up @@ -2025,8 +2028,22 @@ - (id)accessibilityElementAtIndex:(NSInteger)index
}

// Update the accessibility element.
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
CGRect annotationFrame = [self frameOfImage:annotationImage.image centeredAtCoordinate:annotation.coordinate];
MGLAnnotationView *annotationView = annotationContext.annotationView;
CGRect annotationFrame;
if (annotationView && annotationView.superview)
{
annotationFrame = [self convertRect:annotationView.bounds fromView:annotationView];
}
else
{
MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
annotationFrame = [self frameOfImage:annotationImage.image centeredAtCoordinate:annotation.coordinate];
}
CGPoint annotationFrameCenter = CGPointMake(CGRectGetMidX(annotationFrame), CGRectGetMidY(annotationFrame));
CGRect minimumFrame = CGRectInset({ annotationFrameCenter, CGSizeZero },
-MGLAnnotationAccessibilityElementMinimumSize.width / 2,
-MGLAnnotationAccessibilityElementMinimumSize.height / 2);
annotationFrame = CGRectUnion(annotationFrame, minimumFrame);
CGRect screenRect = UIAccessibilityConvertFrameToScreenCoordinates(annotationFrame, self);
annotationContext.accessibilityElement.accessibilityFrame = screenRect;
annotationContext.accessibilityElement.accessibilityHint = NSLocalizedStringWithDefaultValue(@"ANNOTATION_A11Y_HINT", nil, nil, @"Shows more info", @"Accessibility hint");
Expand Down

0 comments on commit 1fdda91

Please sign in to comment.