Skip to content

Commit a95a014

Browse files
SearaChenroycornelissen
authored andcommitted
Add in voiceover accessibility (#32)
+semver: minor
1 parent fc8b8e2 commit a95a014

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/GMImagePicker/GMGridViewCell.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public void Initialize ()
120120

121121
// Note: the views above are created in case this is toggled per cell, on the fly, etc.!
122122
ShouldShowSelection = true;
123+
124+
ConfigureSelectButtonAccessibilityAttributes(_selectedButton, false);
123125
}
124126

125127
// Required to resize the CAGradientLayer because it does not support auto resizing.
@@ -170,6 +172,13 @@ private string GetDurationWithFormat (double duration)
170172
var minutes = (duration / 60) % 60;
171173
return string.Format ("{0:00}:{1:00}", minutes, seconds);
172174
}
175+
176+
#region Voiceover Accessibility Configuration
177+
private static void ConfigureSelectButtonAccessibilityAttributes(UIButton selectButton, bool isSelected)
178+
{
179+
selectButton.AccessibilityElementsHidden = true;
180+
}
181+
#endregion
173182
}
174183
}
175184

src/GMImagePicker/GMGridViewController.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public override void WillAnimateRotation (UIInterfaceOrientation toInterfaceOrie
507507
_imageManager.RequestImageForAsset (typedCell.Asset,
508508
AssetGridThumbnailSize,
509509
PHImageContentMode.AspectFill,
510-
options,
510+
options,
511511
(image, info) => {
512512
// Only update the thumbnail if the cell tag hasn't changed. Otherwise, the cell has been re-used.
513513
if (cell.Tag == currentTag && typedCell.ImageView != null && image != null) {
@@ -563,7 +563,13 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
563563
{
564564
cell.Selected = false;
565565
}
566-
566+
567+
var resources = PHAssetResource.GetAssetResources(asset);
568+
var name = resources != null && resources.Length > 0
569+
? resources[0].OriginalFilename
570+
: string.Empty;
571+
572+
ConfigureSelectCellAccessibilityAttributes(cell, cell.Selected , name);
567573
return cell;
568574
}
569575

@@ -609,7 +615,8 @@ public override bool ShouldSelectItem(UICollectionView collectionView, NSIndexPa
609615
var asset = (PHAsset)AssetsFetchResults[indexPath.Item];
610616

611617
var cell = (GMGridViewCell)collectionView.CellForItem(indexPath);
612-
618+
ConfigureSelectCellAccessibilityAttributes(cell, true, null);
619+
613620
if (!cell.IsEnabled)
614621
{
615622
return false;
@@ -623,12 +630,34 @@ public override bool ShouldSelectItem(UICollectionView collectionView, NSIndexPa
623630
public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath)
624631
{
625632
var asset = (PHAsset)AssetsFetchResults[indexPath.Item];
633+
var cell = (GMGridViewCell)collectionView.CellForItem(indexPath);
626634

627635
_picker.DeselectAsset(asset);
628636
_picker.NotifyAssetDeselected(asset);
637+
ConfigureSelectCellAccessibilityAttributes(cell, false, null);
629638
}
630-
}
639+
640+
#region Voiceover Accessibility Configuration
641+
private static void ConfigureSelectCellAccessibilityAttributes(GMGridViewCell selectedCell, bool isSelected, string imageName)
642+
{
643+
selectedCell.AccessibilityTraits = UIAccessibilityTrait.Button;
644+
selectedCell.IsAccessibilityElement = true;
645+
if (imageName!=null)
646+
{
647+
selectedCell.AccessibilityLabel = imageName;
648+
}
631649

650+
if (!isSelected)
651+
{
652+
selectedCell.AccessibilityHint = "picker.accessibility.check-to-select".Translate(defaultValue: "Check to select the image");
653+
}
654+
else
655+
{
656+
selectedCell.AccessibilityHint = "picker.accessibility.uncheck-to-deselect".Translate(defaultValue: "Uncheck to deselect the image");;
657+
}
658+
}
659+
#endregion
660+
}
632661
#endregion
633662
}
634663

552 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)