Skip to content

Commit

Permalink
[MDCBottomDrawerViewController] Add new delegate for when scrim is ta…
Browse files Browse the repository at this point in the history
…pped.

This adds a new optional MDCBottomDrawerViewController delegate method for when the scrim is tapped.

PiperOrigin-RevId: 324593723
  • Loading branch information
Nobody authored and material-automation committed Aug 3, 2020
1 parent bb04d0a commit f3b77c4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,11 @@ - (void)setupBottomDrawerContainerViewControllerConstraints {
}

- (void)presentationTransitionDidEnd:(BOOL)completed {
if (self.dismissOnBackgroundTap) {
// Set up the tap recognizer to dimiss the drawer by.
UITapGestureRecognizer *tapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDrawer)];
[self.containerView addGestureRecognizer:tapGestureRecognizer];
tapGestureRecognizer.delegate = self;
}
// Set up the tap recognizer.
UITapGestureRecognizer *tapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrimTapped)];
[self.containerView addGestureRecognizer:tapGestureRecognizer];
tapGestureRecognizer.delegate = self;

self.bottomDrawerContainerViewController.animatingPresentation = NO;
[self.bottomDrawerContainerViewController.view setNeedsLayout];
Expand Down Expand Up @@ -393,6 +391,15 @@ - (void)hideDrawer {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)scrimTapped {
[self.delegate bottomDrawerDidTapScrim:self];

// Dismiss the drawer on tap if enabled.
if (self.dismissOnBackgroundTap) {
[self hideDrawer];
}
}

#pragma mark UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@
- (void)bottomDrawerDismissTransitionDidEnd:
(nonnull MDCBottomDrawerPresentationController *)presentationController;

/**
This method is called when the bottom drawer's scrim was tapped.
@param presentationController presentation controller of the bottom drawer
*/
- (void)bottomDrawerDidTapScrim:
(nonnull MDCBottomDrawerPresentationController *)presentationController;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ - (void)bottomDrawerDismissTransitionDidEnd:
}
}

- (void)bottomDrawerDidTapScrim:(MDCBottomDrawerPresentationController *)presentationController {
if ([self.delegate respondsToSelector:@selector(bottomDrawerControllerDidTapScrim:)]) {
[self.delegate bottomDrawerControllerDidTapScrim:self];
}
}

- (void)bottomDrawerPresentTransitionWillBegin:
(MDCBottomDrawerPresentationController *)presentationController
withCoordinator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@
- (void)bottomDrawerControllerDidEndCloseTransition:
(nonnull MDCBottomDrawerViewController *)controller;

/**
Called when the bottom drawer's scrim was tapped.
@param controller The MDCBottomDrawerViewController.
*/
- (void)bottomDrawerControllerDidTapScrim:(nonnull MDCBottomDrawerViewController *)controller;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ - (void)bottomDrawerPresentTransitionWillBegin:
[_commands addObject:NSStringFromSelector(_cmd)];
}

- (void)bottomDrawerDidTapScrim:(MDCBottomDrawerPresentationController *)presentationController {
[_commands addObject:NSStringFromSelector(_cmd)];
}

- (void)bottomDrawerControllerDidEndOpenTransition:(MDCBottomDrawerViewController *)controller {
[_commands addObject:NSStringFromSelector(_cmd)];
}
Expand Down Expand Up @@ -115,6 +119,10 @@ - (void)bottomDrawerControllerWillTransitionOpen:(nonnull MDCBottomDrawerViewCon
[_commands addObject:NSStringFromSelector(_cmd)];
}

- (void)bottomDrawerControllerDidTapScrim:(nonnull MDCBottomDrawerViewController *)controller {
[_commands addObject:NSStringFromSelector(_cmd)];
}

- (void)clear {
_commands = [NSMutableArray array];
}
Expand Down Expand Up @@ -153,6 +161,7 @@ @interface MDCBottomDrawerPresentationController (ScrollViewTests) <
@property(nonatomic) MDCBottomDrawerContainerViewController *bottomDrawerContainerViewController;
@property(nonatomic, weak, nullable) id<MDCBottomDrawerPresentationControllerDelegate> delegate;
@property(nonatomic, strong, nullable) UIView *topHandle;
- (void)scrimTapped;
@end

@interface MDCNavigationDrawerScrollViewTests : XCTestCase
Expand Down Expand Up @@ -596,6 +605,18 @@ - (void)testBottomDrawerControllerToYOffsetChangesCallback {
verifyCallback:@selector(bottomDrawerControllerDidChangeTopYOffset:yOffset:)]);
}

- (void)testBottomDrawerControllerDidTapScrimCallback {
// Given
self.presentationController.delegate = self.delegateTest;
self.presentationController.bottomDrawerContainerViewController = self.fakeBottomDrawer;

// When
[self.presentationController scrimTapped];

// Then
XCTAssertTrue([self.delegateTest verifyCallback:@selector(bottomDrawerDidTapScrim:)]);
}

- (void)testBottomDrawerCornersAPICollapsed {
// When
[self.drawerViewController setTopCornersRadius:10 forDrawerState:MDCBottomDrawerStateCollapsed];
Expand Down

0 comments on commit f3b77c4

Please sign in to comment.