Skip to content

Commit

Permalink
[NavigationDrawer] Add ability to change the maximumInitialDrawerHeig…
Browse files Browse the repository at this point in the history
…ht after drawer has been presented.

PiperOrigin-RevId: 292305019
  • Loading branch information
yarneo authored and material-automation committed Jan 30, 2020
1 parent 62fc063 commit 19c1712
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Expand Up @@ -341,6 +341,12 @@ - (void)setTrackingScrollView:(UIScrollView *)trackingScrollView {
self.bottomDrawerContainerViewController.trackingScrollView = trackingScrollView;
}

- (void)setMaximumInitialDrawerHeight:(CGFloat)maximumInitialDrawerHeight {
_maximumInitialDrawerHeight = maximumInitialDrawerHeight;
self.bottomDrawerContainerViewController.maximumInitialDrawerHeight =
self.maximumInitialDrawerHeight;
}

- (BOOL)contentReachesFullscreen {
return self.bottomDrawerContainerViewController.contentReachesFullscreen;
}
Expand Down
Expand Up @@ -185,6 +185,7 @@ @implementation MDCBottomDrawerContainerViewController {
CGFloat _contentVCPreferredContentSizeHeightCached;
CGFloat _headerVCPerferredContentSizeHeightCached;
CGFloat _scrollToContentOffsetY;
CGFloat _maximumInitialDrawerHeight;
BOOL _shouldPresentAtFullscreen;
}

Expand Down Expand Up @@ -373,6 +374,18 @@ - (CGFloat)maximumInitialDrawerHeight {
return _maximumInitialDrawerHeight + [self bottomSafeAreaInsetsToAdjustInitialDrawerHeight];
}

- (void)setMaximumInitialDrawerHeight:(CGFloat)maximumInitialDrawerHeight {
_maximumInitialDrawerHeight = maximumInitialDrawerHeight;

if (_contentHeaderTopInset != NSNotFound) {
_contentHeaderTopInset = NSNotFound;
_contentHeightSurplus = NSNotFound;
_addedContentHeight = NSNotFound;
[self cacheLayoutCalculations];
[self setupLayout];
}
}

- (void)addScrollViewObserver {
if (self.scrollViewObserved) {
return;
Expand Down
Expand Up @@ -1089,6 +1089,25 @@ - (void)testSettingTrackingScrollViewAfterInit {
XCTAssertEqualObjects(drawerContainer.trackingScrollView, newTrackingScrollView);
}

- (void)testUpdatingMaximumInitialDrawerHeightWithLargePreferredContentSize {
// Given
CGRect fakeRect = CGRectMake(0, 0, 250, 500);
self.fakeBottomDrawer.originalPresentingViewController.view.bounds = fakeRect;
self.fakeBottomDrawer.contentViewController.preferredContentSize = CGSizeMake(250, 1000);

// When
self.fakeBottomDrawer.maximumInitialDrawerHeight = 100;

// Then
XCTAssertEqualWithAccuracy(self.fakeBottomDrawer.contentHeaderTopInset, 400, 0.001);

// When
self.fakeBottomDrawer.maximumInitialDrawerHeight = 300;

// Then
XCTAssertEqualWithAccuracy(self.fakeBottomDrawer.contentHeaderTopInset, 200, 0.001);
}

- (void)testUpdatingPreferredContentSizeWithLargeMaximumInitialDrawerHeight {
// Given
CGRect fakeRect = CGRectMake(0, 0, 250, 500);
Expand Down

0 comments on commit 19c1712

Please sign in to comment.