Skip to content

Commit

Permalink
Fix RTL layout for Collection Cells
Browse files Browse the repository at this point in the history
Summary:
Properly handle RTL in collection cells with accessory views.

AUTHOR:ed-chin

Test Plan: Tested on pseudortl on iOS 9 simulator

Reviewers: O1 Material components iOS, cjcox

Reviewed By: O1 Material components iOS, cjcox

Tags: #material_components_ios

Differential Revision: http://codereview.cc/D1449
  • Loading branch information
edx246 authored and Ian Gordon committed Aug 11, 2016
1 parent 09b9fcc commit 9a0804f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/CollectionCells/src/MDCCollectionViewCell.m
Expand Up @@ -188,6 +188,12 @@ - (void)layoutForegroundSubviews {
_accessoryView.frame = [self accessoryFrame];
// Then lay out the content view, inset by the accessory view's width.
self.contentView.frame = [self contentViewFrame];

// If necessary flip subviews for RTL.
_accessoryView.frame = MDCRectFlippedForRTL(_accessoryView.frame, CGRectGetWidth(self.bounds),
self.mdc_effectiveUserInterfaceLayoutDirection);
self.contentView.frame = MDCRectFlippedForRTL(self.contentView.frame, CGRectGetWidth(self.bounds),
self.mdc_effectiveUserInterfaceLayoutDirection);
}

#pragma mark - Accessory Views
Expand Down Expand Up @@ -247,9 +253,7 @@ - (CGRect)accessoryFrame {
CGSize size = _accessoryView.frame.size;
CGFloat originX = CGRectGetWidth(self.bounds) - size.width - _accessoryInset.right;
CGFloat originY = (CGRectGetHeight(self.bounds) - size.height) / 2;
CGRect frame = CGRectMake(originX, originY, size.width, size.height);
return MDCRectFlippedForRTL(frame, CGRectGetWidth(self.bounds),
self.mdc_effectiveUserInterfaceLayoutDirection);
return CGRectMake(originX, originY, size.width, size.height);
}

#pragma mark - Separator
Expand Down Expand Up @@ -442,8 +446,7 @@ - (CGRect)contentViewFrame {
_attr.shouldShowSelectorStateMask
? CGRectGetWidth(_editingSelectorImageView.bounds) + kEditingControlAppearanceOffset
: accessoryViewPadding;
UIEdgeInsets insets = MDCInsetsMakeWithLayoutDirection(
0, leadingPadding, 0, trailingPadding, self.mdc_effectiveUserInterfaceLayoutDirection);
UIEdgeInsets insets = UIEdgeInsetsMake(0, leadingPadding, 0, trailingPadding);
return UIEdgeInsetsInsetRect(self.bounds, insets);
}

Expand Down

0 comments on commit 9a0804f

Please sign in to comment.