Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit cc7e285

Browse files
committed
Merge branch 'develop' into issue/improve_permission_handling
2 parents 0e52dbb + a09bdb2 commit cc7e285

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

Pod/Classes/WPMediaCaptureCollectionViewCell.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,14 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification
107107
}
108108
}
109109

110+
- (BOOL)isAccessibilityElement
111+
{
112+
return YES;
113+
}
114+
115+
- (NSString *)accessibilityLabel
116+
{
117+
return NSLocalizedString(@"Camera", @"Accessibility label for the camera tile in the collection view");
118+
}
119+
110120
@end

Pod/Classes/WPMediaCollectionViewCell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
- (void)setCaption:(NSString *)caption;
99

10-
- (void)setImage:(UIImage *)image animated:(BOOL)animated;
10+
- (void)setImage:(UIImage *)image animated:(BOOL)animated withAccessibilityLabel:(NSString*)accessibilityLabel;
1111

1212
@end

Pod/Classes/WPMediaCollectionViewCell.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ - (void)prepareForReuse
4040
- (void)commonInit
4141
{
4242
_imageView = [[UIImageView alloc] init];
43+
_imageView.isAccessibilityElement = YES;
4344
_imageView.contentMode = UIViewContentModeScaleAspectFill;
4445
_imageView.clipsToBounds = YES;
4546
_imageView.backgroundColor = self.backgroundColor;
@@ -70,25 +71,28 @@ - (void)commonInit
7071
[self.contentView addSubview:_captionLabel];
7172
}
7273

73-
- (void)setImage:(UIImage *)image
74+
- (void)setImage:(UIImage *)image withAccessibilityLabel:(NSString*)accessibilityLabel
7475
{
75-
[self setImage:image animated:YES];
76+
[self setImage:image animated:YES withAccessibilityLabel:accessibilityLabel];
7677
}
7778

78-
- (void)setImage:(UIImage *)image animated:(BOOL)animated
79+
- (void)setImage:(UIImage *)image animated:(BOOL)animated withAccessibilityLabel:(NSString*)accessibilityLabel
7980
{
8081
if (!image){
8182
self.imageView.alpha = 0;
8283
self.imageView.image = nil;
84+
self.imageView.accessibilityLabel = nil;
8385
} else {
8486
if (animated) {
8587
[UIView animateWithDuration:0.3 animations:^{
8688
self.imageView.alpha = 1.0;
8789
self.imageView.image = image;
90+
self.imageView.accessibilityLabel = accessibilityLabel;
8891
}];
8992
} else {
9093
self.imageView.alpha = 1.0;
9194
self.imageView.image = image;
95+
self.imageView.accessibilityLabel = accessibilityLabel;
9296
}
9397
}
9498
}

Pod/Classes/WPMediaCollectionViewController.m

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,24 @@ - (BOOL)isCaptureCellIndexPath:(NSIndexPath *)indexPath
351351
return asset;
352352
}
353353

354+
- (NSString *)accessibilityLabelForType:(WPMediaType)assetType atIndexPath:(NSInteger)index
355+
{
356+
NSString *accessibilityLabelFormat;
357+
switch (assetType) {
358+
case WPMediaTypeImage:
359+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d, image.", @"Accessibility label for image thumbnails in the media collection view. The parameter is the index of the image in the collection view.");
360+
break;
361+
case WPMediaTypeVideo:
362+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d, video", @"Accessibility label for video thumbnails in the media collection view. The parameter is the index of the video in the collection view.");
363+
break;
364+
default:
365+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d", @"Accessibility label for asset (of unknown type) thumbnails in the media collection view. The parameter is the index of the asset in the collection view.");
366+
break;
367+
}
368+
369+
return [NSString stringWithFormat:accessibilityLabelFormat, index];
370+
}
371+
354372
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
355373
{
356374
if ([self isCaptureCellIndexPath:indexPath]) {
@@ -368,22 +386,29 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
368386
// Configure the cell
369387
__block WPMediaRequestID requestKey = 0;
370388
NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
389+
NSInteger itemIndex = indexPath.item + 1; // Asset position + 1 to avoid starting at "Asset 0"
390+
WPMediaType assetType = asset.assetType;
371391
requestKey = [asset imageWithSize:cell.frame.size completionHandler:^(UIImage *result, NSError *error) {
372392
BOOL animated = ([NSDate timeIntervalSinceReferenceDate] - timestamp) > 0.03;
373393
if (error) {
374394
cell.image = nil;
375395
NSLog(@"%@", [error localizedDescription]);
376396
return;
377397
}
378-
if ([NSThread isMainThread]){
398+
void (^setImage)() = ^{
379399
if (requestKey == cell.tag){
380-
[cell setImage:result animated:animated];
400+
NSString *accessibilityLabel = [self accessibilityLabelForType:assetType
401+
atIndexPath:itemIndex];
402+
[cell setImage:result
403+
animated:animated
404+
withAccessibilityLabel:accessibilityLabel];
381405
}
406+
};
407+
if ([NSThread isMainThread]){
408+
setImage();
382409
} else {
383410
dispatch_async(dispatch_get_main_queue(), ^{
384-
if (requestKey == cell.tag){
385-
[cell setImage:result animated:animated];
386-
}
411+
setImage();
387412
});
388413
}
389414
}];

0 commit comments

Comments
 (0)