Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 394725753
  • Loading branch information
Jeff Verkoeyen authored and material-automation committed Sep 3, 2021
1 parent 1b69273 commit ec44b12
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 249 deletions.
14 changes: 4 additions & 10 deletions components/ActionSheet/src/MDCActionSheetController.m
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,8 @@ - (void)viewDidLoad {
self.tableView.frame = self.view.bounds;
self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
self.view.preservesSuperviewLayoutMargins = YES;
if (@available(iOS 11.0, *)) {
self.view.insetsLayoutMarginsFromSafeArea = NO;
self.tableView.insetsLayoutMarginsFromSafeArea = NO;
}
self.view.insetsLayoutMarginsFromSafeArea = NO;
self.tableView.insetsLayoutMarginsFromSafeArea = NO;
[self.view addSubview:self.tableView];
[self.view addSubview:self.header];
[self.view addSubview:self.headerDividerView];
Expand All @@ -244,9 +242,7 @@ - (void)viewDidLayoutSubviews {
self.headerDividerView.frame =
CGRectMake(0, size.height, CGRectGetWidth(self.view.bounds), dividerHeight);
UIEdgeInsets insets = UIEdgeInsetsMake(size.height + dividerHeight, 0, 0, 0);
if (@available(iOS 11.0, *)) {
insets.bottom = self.tableView.adjustedContentInset.bottom;
}
insets.bottom = self.tableView.adjustedContentInset.bottom;
self.tableView.contentInset = insets;
self.tableView.contentOffset = CGPointMake(0, -size.height);
}
Expand All @@ -268,9 +264,7 @@ - (CGFloat)openingSheetHeight {
(((CGFloat)amountOfCellsToShow - (CGFloat)0.5) * cellHeight) + headerHeight;
// When updating the preferredSheetHeight the presentation controller takes into account the
// safe area so we have to remove that.
if (@available(iOS 11.0, *)) {
preferredHeight = preferredHeight - self.tableView.adjustedContentInset.bottom;
}
preferredHeight = preferredHeight - self.tableView.adjustedContentInset.bottom;
return ceil(preferredHeight);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,9 @@ - (void)setupExampleViews {
self.scrollView.clipsToBounds = YES;
[self.view addSubview:self.scrollView];

if (@available(iOS 11.0, *)) {
// No need to do anything - additionalSafeAreaInsets will inset our content.
self.scrollView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
} else {
self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[NSLayoutConstraint constraintWithItem:self.scrollView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.topLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0],
[NSLayoutConstraint constraintWithItem:self.scrollView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0],
[NSLayoutConstraint constraintWithItem:self.scrollView
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0],
[NSLayoutConstraint constraintWithItem:self.scrollView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0]
]];
}
// No need to do anything - additionalSafeAreaInsets will inset our content.
self.scrollView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

CGFloat lineSpace = (CGRectGetHeight(self.view.frame) - 50) / 5;
UILabel *linearLabel = [AnimationTimingExampleViewController curveLabelWithTitle:@"Linear"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ - (void)viewWillLayoutSubviews {
}

- (void)viewSafeAreaInsetsDidChange {
if (@available(iOS 11.0, *)) {
[super viewSafeAreaInsetsDidChange];
}
[super viewSafeAreaInsetsDidChange];
[self layoutBottomAppBar];
}

Expand Down
10 changes: 3 additions & 7 deletions components/BottomAppBar/src/MDCBottomAppBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ - (CGPoint)getFloatingButtonCenterPositionForAppBarWidth:(CGFloat)appBarWidth {
floatingButtonPoint.y = MAX(0, navigationBarMinY - self.floatingButtonVerticalOffset);

UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
safeAreaInsets = self.safeAreaInsets;
}
safeAreaInsets = self.safeAreaInsets;

CGFloat leftCenter = kMDCBottomAppBarFloatingButtonPositionX + safeAreaInsets.left;
CGFloat rightCenter =
Expand Down Expand Up @@ -276,10 +274,8 @@ - (void)layoutSubviews {

- (UIEdgeInsets)mdc_safeAreaInsets {
UIEdgeInsets insets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
// Accommodate insets for iPhone X.
insets = self.safeAreaInsets;
}
// Accommodate insets for iPhone X.
insets = self.safeAreaInsets;
return insets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
*/
static UIImage *_Nullable MDCImageForItem(UITabBarItem *_Nonnull item) {
UIImage *image;
if (@available(iOS 11, *)) {
image = item.largeContentSizeImage;
}
image = item.largeContentSizeImage;

return image ?: item.image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,12 @@ - (void)viewDidLoad {
[stackView addArrangedSubview:
self.bottomSheetPresentationControllerDismissalAnimationCompletedCalledLabel];

if (@available(iOS 11.0, *)) {
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active =
YES;
[stackView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor]
.active = YES;
[stackView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor]
.active = YES;
} else {
[stackView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES;
[stackView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[stackView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
}
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active =
YES;
[stackView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor]
.active = YES;
[stackView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor]
.active = YES;
}

- (void)presentBottomSheet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ - (void)presentationTransitionWillBegin {
}
CGRect sheetFrame = [self frameOfPresentedViewInContainerView];
if (self.shouldPropagateSafeAreaInsetsToPresentedViewController) {
if (@available(iOS 11.0, *)) {
self.presentedViewController.additionalSafeAreaInsets =
self.presentingViewController.view.safeAreaInsets;
}
self.presentedViewController.additionalSafeAreaInsets =
self.presentingViewController.view.safeAreaInsets;
}
self.sheetView = [[MDCSheetContainerView alloc] initWithFrame:sheetFrame
contentView:self.presentedViewController.view
Expand Down
42 changes: 17 additions & 25 deletions components/BottomSheet/src/private/MDCSheetContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ - (instancetype)initWithFrame:(CGRect)frame

// Since we handle the SafeAreaInsets ourselves through the contentInset property, we disable
// the adjustment behavior to prevent accounting for it twice.
if (@available(iOS 11.0, *)) {
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
scrollView.preservesSuperviewLayoutMargins = YES;
}
return self;
Expand Down Expand Up @@ -171,24 +169,22 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
}

- (void)safeAreaInsetsDidChange {
if (@available(iOS 11.0, *)) {
[super safeAreaInsetsDidChange];

if (self.adjustHeightForSafeAreaInsets) {
_preferredSheetHeight = self.originalPreferredSheetHeight + self.safeAreaInsets.bottom;
[super safeAreaInsetsDidChange];

UIEdgeInsets contentInset = self.sheet.scrollView.contentInset;
contentInset.bottom = MAX(contentInset.bottom, self.safeAreaInsets.bottom);
self.sheet.scrollView.contentInset = contentInset;
}
CGRect scrollViewFrame = CGRectStandardize(self.sheet.scrollView.frame);
scrollViewFrame.size = CGSizeMake(scrollViewFrame.size.width, CGRectGetHeight(self.frame));
self.sheet.scrollView.frame = scrollViewFrame;
if (self.adjustHeightForSafeAreaInsets) {
_preferredSheetHeight = self.originalPreferredSheetHeight + self.safeAreaInsets.bottom;

// Note this is needed to make sure the full displayed frame updates to reflect the new safe
// area insets after rotation. See b/183357841 for context.
[self updateSheetFrame];
UIEdgeInsets contentInset = self.sheet.scrollView.contentInset;
contentInset.bottom = MAX(contentInset.bottom, self.safeAreaInsets.bottom);
self.sheet.scrollView.contentInset = contentInset;
}
CGRect scrollViewFrame = CGRectStandardize(self.sheet.scrollView.frame);
scrollViewFrame.size = CGSizeMake(scrollViewFrame.size.width, CGRectGetHeight(self.frame));
self.sheet.scrollView.frame = scrollViewFrame;

// Note this is needed to make sure the full displayed frame updates to reflect the new safe
// area insets after rotation. See b/183357841 for context.
[self updateSheetFrame];
}

#pragma mark - KVO
Expand Down Expand Up @@ -228,10 +224,8 @@ - (void)layoutSubviews {

- (void)updateSheetHeight {
CGFloat adjustedPreferredSheetHeight = self.originalPreferredSheetHeight;
if (@available(iOS 11.0, *)) {
if (self.adjustHeightForSafeAreaInsets) {
adjustedPreferredSheetHeight += self.safeAreaInsets.bottom;
}
if (self.adjustHeightForSafeAreaInsets) {
adjustedPreferredSheetHeight += self.safeAreaInsets.bottom;
}

if (_preferredSheetHeight == adjustedPreferredSheetHeight) {
Expand Down Expand Up @@ -312,9 +306,7 @@ - (CGFloat)scrollViewContentHeight {
// Returns the maximum allowable height that the sheet can be dragged to.
- (CGFloat)maximumSheetHeight {
CGFloat boundsHeight = CGRectGetHeight(self.bounds);
if (@available(iOS 11.0, *)) {
boundsHeight -= self.safeAreaInsets.top;
}
boundsHeight -= self.safeAreaInsets.top;
// If we have a scrollview, the sheet should never get taller than its content height.
CGFloat contentHeight = [self scrollViewContentHeight];
if (contentHeight > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ - (void)viewDidLayoutSubviews {
CGSize largeIconFabSize = self.largeIconFloatingButton.intrinsicContentSize;

CGFloat xOffset = CGRectGetMinX(bounds) + 20;
if (@available(iOS 11.0, *)) {
xOffset += self.view.safeAreaInsets.left;
}
xOffset += self.view.safeAreaInsets.left;

if (!self.iPadLabel.hidden) {
self.iPadLabel.center = CGPointMake(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,7 @@ - (UILabel *)addLabelWithText:(NSString *)text {
}

- (CGRect)contentBounds {
CGRect bounds = self.view.bounds;
__block CGRect contentBounds = CGRectZero;

void (^preiOS11Behavior)(void) = ^{
CGRect safeAreaBounds;
CGRectDivide(bounds, &safeAreaBounds, &contentBounds, self.topLayoutGuide.length,
CGRectMinYEdge);
};
if (@available(iOS 11.0, *)) {
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
contentBounds = UIEdgeInsetsInsetRect(bounds, safeAreaInsets);
} else {
preiOS11Behavior();
}

return contentBounds;
return UIEdgeInsetsInsetRect(self.view.bounds, self.view.safeAreaInsets);
}

- (void)viewDidLayoutSubviews {
Expand Down
4 changes: 1 addition & 3 deletions components/Collections/examples/CollectionsALaCarteExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ - (void)viewDidLoad {
collectionViewLayout:self.collectionViewLayout];
self.collectionView = _customCollectionView;

if (@available(iOS 11.0, *)) {
_customCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
}
_customCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;

// Register cell class.
[self.collectionView registerClass:[MDCCollectionViewTextCell class]
Expand Down
6 changes: 2 additions & 4 deletions components/Collections/src/private/MDCCollectionInfoBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ - (void)layoutSubviews {
[super layoutSubviews];

UIEdgeInsets collectionViewSafeAreaInsets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
if (self.superview) {
collectionViewSafeAreaInsets = self.superview.safeAreaInsets;
}
if (self.superview) {
collectionViewSafeAreaInsets = self.superview.safeAreaInsets;
}
CGFloat leftInset =
MAX(MDCCollectionInfoBarLabelHorizontalPadding, collectionViewSafeAreaInsets.left);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ - (IBAction)didTapPresent:(id)sender {
NSString *urduFontName = @"NotoNastaliqUrdu";
UIFont *dialogBodyFont = [UIFont systemFontOfSize:20.0];
UIFont *dialogButtonFont = [UIFont systemFontOfSize:20.0];
if (@available(iOS 11, *)) {
// Noto Nastaliq Urdu was added in iOS 11, and is an extremely tall
// font for any given nominal point size.
dialogBodyFont = [UIFont fontWithName:urduFontName size:20.0];
dialogButtonFont = [UIFont fontWithName:urduFontName size:20.0];
}
// Noto Nastaliq Urdu was added in iOS 11, and is an extremely tall
// font for any given nominal point size.
dialogBodyFont = [UIFont fontWithName:urduFontName size:20.0];
dialogButtonFont = [UIFont fontWithName:urduFontName size:20.0];
alert.messageFont = dialogBodyFont;
MDCButton *buttonForRetryAction = [alert buttonForAction:retryAction];
buttonForRetryAction.titleLabel.font = dialogButtonFont;
Expand Down
4 changes: 1 addition & 3 deletions components/Dialogs/src/MDCDialogPresentationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ - (CGRect)frameOfPresentedViewInContainerView {

// For pre iOS 11 devices, we are assuming a safeAreaInset of UIEdgeInsetsZero
UIEdgeInsets containerSafeAreaInsets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
containerSafeAreaInsets = self.containerView.safeAreaInsets;
}
containerSafeAreaInsets = self.containerView.safeAreaInsets;

// Take the larger of the Safe Area insets and the Material specified insets.
containerSafeAreaInsets.top = MAX(containerSafeAreaInsets.top, MDCDialogEdgeInsets.top);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ - (void)extractTopSafeAreaInset {
return;
}

if (@available(iOS 11.0, *)) {
CGFloat safeAreaTop = viewController.view.safeAreaInsets.top;
if (self.subtractsAdditionalSafeAreaInsets) {
safeAreaTop -= viewController.additionalSafeAreaInsets.top;
}
self.extractedTopSafeAreaInset = safeAreaTop;
} else {
self.extractedTopSafeAreaInset = viewController.topLayoutGuide.length;
CGFloat safeAreaTop = viewController.view.safeAreaInsets.top;
if (self.subtractsAdditionalSafeAreaInsets) {
safeAreaTop -= viewController.additionalSafeAreaInsets.top;
}
self.extractedTopSafeAreaInset = safeAreaTop;
}

@end
16 changes: 5 additions & 11 deletions components/Ink/examples/InkTypicalUse.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,11 @@ - (void)setupExampleViews {
}

- (void)viewWillLayoutSubviews {
if (@available(iOS 11.0, *)) {
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
self.containerView.frame =
CGRectMake(safeAreaInsets.left, safeAreaInsets.top,
CGRectGetWidth(self.view.frame) - safeAreaInsets.left - safeAreaInsets.right,
CGRectGetHeight(self.view.frame) - safeAreaInsets.top - safeAreaInsets.bottom);
} else {
self.containerView.frame =
CGRectMake(0, self.topLayoutGuide.length, CGRectGetWidth(self.view.frame),
CGRectGetHeight(self.view.frame) - self.topLayoutGuide.length);
}
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
self.containerView.frame =
CGRectMake(safeAreaInsets.left, safeAreaInsets.top,
CGRectGetWidth(self.view.frame) - safeAreaInsets.left - safeAreaInsets.right,
CGRectGetHeight(self.view.frame) - safeAreaInsets.top - safeAreaInsets.bottom);

CGFloat offset = 8;
CGFloat shapeDimension = 200;
Expand Down
Loading

0 comments on commit ec44b12

Please sign in to comment.