Skip to content

Commit

Permalink
Adjust content view frame when safe area insets change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 365882840
  • Loading branch information
afweiss authored and material-automation committed Mar 30, 2021
1 parent d5d2306 commit ac810a4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions components/BottomSheet/src/private/MDCSheetContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
return;
}

[self updateSheetFrame];
// Adjusts the pane to the correct snap point, e.g. after a rotation.
if (self.window) {
[self animatePaneWithInitialVelocity:CGPointZero];
}
[self updateSheetFrameRemoveAnimations:YES];
}

- (void)safeAreaInsetsDidChange {
Expand All @@ -187,6 +183,10 @@ - (void)safeAreaInsetsDidChange {
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 updateSheetFrameRemoveAnimations:NO];
}
}

Expand Down Expand Up @@ -238,12 +238,7 @@ - (void)updateSheetHeight {
}
_preferredSheetHeight = adjustedPreferredSheetHeight;

[self updateSheetFrame];

// Adjusts the pane to the correct snap point if we are visible.
if (self.window) {
[self animatePaneWithInitialVelocity:CGPointZero];
}
[self updateSheetFrameRemoveAnimations:YES];
}

- (void)setPreferredSheetHeight:(CGFloat)preferredSheetHeight {
Expand All @@ -257,8 +252,10 @@ - (void)setAdjustHeightForSafeAreaInsets:(BOOL)adjustHeightForSafeAreaInsets {
}

// Slides the sheet position downwards, so the right amount peeks above the bottom of the superview.
- (void)updateSheetFrame {
[self.animator removeAllBehaviors];
- (void)updateSheetFrameRemoveAnimations:(BOOL)removeAnimations {
if (removeAnimations) {
[self.animator removeAllBehaviors];
}

CGRect sheetRect = self.bounds;
sheetRect.origin.y = CGRectGetMaxY(self.bounds) - [self effectiveSheetHeight];
Expand All @@ -274,6 +271,11 @@ - (void)updateSheetFrame {
contentFrame.size.height = [self effectiveSheetHeight];
}
self.contentView.frame = contentFrame;

// Adjusts the pane to the correct snap point, e.g. after a rotation.
if (self.window) {
[self animatePaneWithInitialVelocity:CGPointZero];
}
}

- (void)updateSheetState {
Expand Down

0 comments on commit ac810a4

Please sign in to comment.