[BottomSheet] Adds a setting to make sheets impossible to dismiss.
Exported from an internally lgtm'ed CL: cl/192175794
MODIFY
components/BottomSheet/src/MDCBottomSheetController.h
components/BottomSheet/src/MDCBottomSheetController.h
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
/**
The bottom sheet delegate.
*/

MODIFY
components/BottomSheet/src/MDCBottomSheetController.m
components/BottomSheet/src/MDCBottomSheetController.m
super.transitioningDelegate = _transitionController;
super.modalPresentationStyle = UIModalPresentationCustom;
+ self.dismissOnBackgroundTap = YES;
}
return self;
}
}
- (BOOL)accessibilityPerformEscape {
+ if (!self.dismissOnBackgroundTap) {
+ return NO;
+ }
[self dismissViewControllerAnimated:YES completion:nil];
return YES;
}
_transitionController.trackingScrollView = trackingScrollView;
}
+- (BOOL)dismissOnBackgroundTap {
+ return _transitionController.dismissOnBackgroundTap;
+}
+
+- (void)setDismissOnBackgroundTap:(BOOL)dismissOnBackgroundTap {
+ _transitionController.dismissOnBackgroundTap = dismissOnBackgroundTap;
+ self.mdc_bottomSheetPresentationController.dismissOnBackgroundTap = dismissOnBackgroundTap;
+}
+
/* Disable setter. Always use internal transition controller */
- (void)setTransitioningDelegate:
(__unused id<UIViewControllerTransitioningDelegate>)transitioningDelegate {

MODIFY
components/BottomSheet/src/MDCBottomSheetPresentationController.h
components/BottomSheet/src/MDCBottomSheetPresentationController.h
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
/**
Delegate to tell the presenter when to dismiss.
*/

MODIFY
components/BottomSheet/src/MDCBottomSheetPresentationController.m
components/BottomSheet/src/MDCBottomSheetPresentationController.m
@@ -174,6 +174,9 @@ static UIScrollView *MDCBottomSheetGetPrimaryScrollView(UIViewController *viewCo
}
- (void)dismissPresentedControllerIfNecessary:(UITapGestureRecognizer *)tapRecognizer {
+ if (!_dismissOnBackgroundTap) {
+ return;
+ }
// Only dismiss if the tap is outside of the presented view.
UIView *contentView = self.presentedViewController.view;
CGPoint pointInContentView = [tapRecognizer locationInView:contentView];

MODIFY
components/BottomSheet/src/MDCBottomSheetTransitionController.h
components/BottomSheet/src/MDCBottomSheetTransitionController.h
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
@end

MODIFY
components/BottomSheet/src/MDCBottomSheetTransitionController.m
components/BottomSheet/src/MDCBottomSheetTransitionController.m
@@ -32,6 +32,7 @@ static const NSTimeInterval MDCBottomSheetTransitionDuration = 0.25;
[[MDCBottomSheetPresentationController alloc] initWithPresentedViewController:presented
presentingViewController:presenting];
presentationController.trackingScrollView = self.trackingScrollView;
+ presentationController.dismissOnBackgroundTap = self.dismissOnBackgroundTap;
return presentationController;
}

[BottomSheet] Adds a setting to make sheets impossible to dismiss. (#3325)

Exported from an internally lgtm'ed CL: cl/192175794