Skip to content

Commit

Permalink
Add iOS 7 compatible fallback for accessibilityElements
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali authored and jimmymlu committed Sep 4, 2015
1 parent 42b4399 commit 7dc1319
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions SleepModel/HEMBreakdownViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
@property (nonatomic, weak) IBOutlet UILabel* itemTitle2;
@property (nonatomic, weak) IBOutlet UILabel* itemValue1;
@property (nonatomic, weak) IBOutlet UILabel* itemValue2;

/**
* Convenience container for accessibility elements
*/
@property (nonatomic, strong) NSArray* computedAccessibilityElements;
@end
19 changes: 17 additions & 2 deletions SleepModel/HEMBreakdownViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ - (UICollectionViewCell *)metricCellInCollectionView:(UICollectionView *)collect
[collectionView dequeueReusableCellWithReuseIdentifier:[HEMMainStoryboard breakdownLineCellReuseIdentifier]
forIndexPath:indexPath];
cell.isAccessibilityElement = NO;
cell.accessibilityElements = @[];
cell.computedAccessibilityElements = @[];
[self collectionView:collectionView updateMetricInCell:cell atIndexPath:indexPath inPosition:0];
[self collectionView:collectionView updateMetricInCell:cell atIndexPath:indexPath inPosition:1];
return cell;
Expand All @@ -210,7 +210,7 @@ - (void)collectionView:(UICollectionView *)collectionView
frame.origin.x = position * width;
frame.size.width = width;
element.accessibilityFrame = frame;
cell.accessibilityElements = [cell.accessibilityElements arrayByAddingObject:element];
cell.computedAccessibilityElements = [cell.computedAccessibilityElements arrayByAddingObject:element];
}

- (NSAttributedString *)titleForItemAtIndexPath:(NSIndexPath *)indexPath position:(NSUInteger)position {
Expand Down Expand Up @@ -352,4 +352,19 @@ @implementation HEMBreakdownSummaryCell
@end

@implementation HEMBreakdownLineCell

- (id)accessibilityElementAtIndex:(NSInteger)index {
if (self.computedAccessibilityElements.count > index)
return self.computedAccessibilityElements[index];
return nil;
}

- (NSInteger)accessibilityElementCount {
return self.computedAccessibilityElements.count;
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
return [self.computedAccessibilityElements indexOfObject:element];
}

@end
20 changes: 19 additions & 1 deletion SleepModel/HEMSleepSummaryCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,31 @@ - (void)awakeFromNib {
self.messageContainerView.accessibilityLabel = NSLocalizedString(@"timeline.accessibility-label.breakdown", nil);
self.messageContainerView.accessibilityHint = NSLocalizedString(@"timeline.accessibility-hint.breakdown", nil);
self.messageContainerView.accessibilityTraits = UIAccessibilityTraitButton;
self.accessibilityElements = @[ self.sleepScoreGraphView, self.messageContainerView ];
}

- (void)prepareForReuse {
[super prepareForReuse];
[self.sleepScoreGraphView setLoading:NO];
}

- (NSInteger)accessibilityElementCount {
return 2;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
if (index == 0)
return self.sleepScoreGraphView;
return self.messageContainerView;
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
if ([element isEqual:self.sleepScoreGraphView])
return 0;
else if ([element isEqual:self.messageContainerView])
return 1;
return NSNotFound;
}

- (void)setLoading:(BOOL)loading {
[self.sleepScoreGraphView setLoading:loading];
}
Expand Down

3 comments on commit 7dc1319

@kattrali
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is messed up. I deleted this when we moved to iOS 8+. Seems to be some rebase thing since I'm the commit author but you're the commit committer.

@jimmymlu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think however this was done is what is causing the conflicts. if you look at the final resulting changes, this has indeed been reverted. It's basically replaying the commit history.

@kattrali
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change may have been reverted, but these commits already exist in develop. This is how we end up in situations where the develop branch is not mergeable to master since the same changes is being applied multiple times through branch conflicts.

Please sign in to comment.