Skip to content
Permalink
Browse files

[BottomSheet] Dismiss BottomSheet with UIAccessibility (#4475)

VoiceOver and switch device users currently have to use the accessibility
escape gesture to dismiss a Bottom Sheet. Optionally, the BottomSheet can use
the dimmed "scrim" area (which can be tappable) to dismiss the bottom sheet
using accessibility technologies.

Obsoletes and closes #4275
  • Loading branch information
romoore authored and ianegordon committed Jul 10, 2018
1 parent 3507c8d commit 031d797ecf188c9994701ab90aad3b31603b6a55
@@ -52,6 +52,35 @@
*/
@property(nonatomic, assign) BOOL dismissOnBackgroundTap;

/**
If @c YES, then the dimmed scrim view will act as an accessibility element for dismissing the
bottom sheet.
Defaults to @c NO.
*/
@property(nonatomic, assign) BOOL isScrimAccessibilityElement;

/**
The @c accessibilityLabel value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityLabel;

/**
The @c accessibilityHint value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityHint;

/**
The @c accessibilityTraits of the dimmed scrim view.
Defaults to @c UIAccessibilityTraitButton.
*/
@property(nonatomic, assign) UIAccessibilityTraits scrimAccessibilityTraits;

/**
The bottom sheet delegate.
*/
@@ -171,6 +171,38 @@ - (void)setModalPresentationStyle:(__unused UIModalPresentationStyle)modalPresen
return;
}

- (void)setIsScrimAccessibilityElement:(BOOL)isScrimAccessibilityElement {
_transitionController.isScrimAccessibilityElement = isScrimAccessibilityElement;
}

- (BOOL)isScrimAccessibilityElement {
return _transitionController.isScrimAccessibilityElement;
}

- (void)setScrimAccessibilityLabel:(NSString *)scrimAccessibilityLabel {
_transitionController.scrimAccessibilityLabel = scrimAccessibilityLabel;
}

- (NSString *)scrimAccessibilityLabel {
return _transitionController.scrimAccessibilityLabel;
}

- (void)setScrimAccessibilityHint:(NSString *)scrimAccessibilityHint {
_transitionController.scrimAccessibilityHint = scrimAccessibilityHint;
}

- (NSString *)scrimAccessibilityHint {
return _transitionController.scrimAccessibilityHint;
}

- (void)setScrimAccessibilityTraits:(UIAccessibilityTraits)scrimAccessibilityTraits {
_transitionController.scrimAccessibilityTraits = scrimAccessibilityTraits;
}

- (UIAccessibilityTraits)scrimAccessibilityTraits {
return _transitionController.scrimAccessibilityTraits;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)bottomSheetPresentationControllerDidDismissBottomSheet:
@@ -66,6 +66,35 @@
*/
@property(nonatomic, assign) BOOL dismissOnBackgroundTap;

/**
If @c YES, then the dimmed scrim view will act as an accessibility element for dismissing the
bottom sheet.
Defaults to @c NO.
*/
@property(nonatomic, assign) BOOL isScrimAccessibilityElement;

/**
The @c accessibilityLabel value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityLabel;

/**
The @c accessibilityHint value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityHint;

/**
The @c accessibilityTraits of the dimmed scrim view.
Defaults to @c UIAccessibilityTraitButton.
*/
@property(nonatomic, assign) UIAccessibilityTraits scrimAccessibilityTraits;

/**
Delegate to tell the presenter when to dismiss.
*/
@@ -47,6 +47,10 @@ @interface MDCBottomSheetPresentationController () <MDCSheetContainerViewDelegat
@implementation MDCBottomSheetPresentationController {
UIView *_dimmingView;
MDCSheetContainerView *_sheetView;
@private BOOL _scrimIsAccessibilityElement;
@private NSString *_scrimAccessibilityLabel;
@private NSString *_scrimAccessibilityHint;
@private UIAccessibilityTraits _scrimAccessibilityTraits;
}

@synthesize delegate;
@@ -83,6 +87,11 @@ - (void)presentationTransitionWillBegin {
_dimmingView.translatesAutoresizingMaskIntoConstraints = NO;
_dimmingView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_dimmingView.accessibilityTraits |= UIAccessibilityTraitButton;
_dimmingView.isAccessibilityElement = _scrimIsAccessibilityElement;
_dimmingView.accessibilityTraits = _scrimAccessibilityTraits;
_dimmingView.accessibilityLabel = _scrimAccessibilityLabel;
_dimmingView.accessibilityHint = _scrimAccessibilityHint;

UIScrollView *scrollView = self.trackingScrollView;
if (scrollView == nil) {
@@ -189,6 +198,44 @@ - (void)dismissPresentedControllerIfNecessary:(UITapGestureRecognizer *)tapRecog
}
}

#pragma mark - Properties

- (void)setIsScrimAccessibilityElement:(BOOL)isScrimAccessibilityElement {
_scrimIsAccessibilityElement = isScrimAccessibilityElement;
_dimmingView.isAccessibilityElement = isScrimAccessibilityElement;
}

- (BOOL)isScrimAccessibilityElement {
return _scrimIsAccessibilityElement;
}

- (void)setScrimAccessibilityLabel:(NSString *)scrimAccessibilityLabel {
_scrimAccessibilityLabel = scrimAccessibilityLabel;
_dimmingView.accessibilityLabel = scrimAccessibilityLabel;
}

- (NSString *)scrimAccessibilityLabel {
return _scrimAccessibilityLabel;
}

- (void)setScrimAccessibilityHint:(NSString *)scrimAccessibilityHint {
_scrimAccessibilityHint = scrimAccessibilityHint;
_dimmingView.accessibilityHint = scrimAccessibilityHint;
}

- (NSString *)scrimAccessibilityHint {
return _scrimAccessibilityHint;
}

- (void)setScrimAccessibilityTraits:(UIAccessibilityTraits)scrimAccessibilityTraits {
_scrimAccessibilityTraits = scrimAccessibilityTraits;
_dimmingView.accessibilityTraits = scrimAccessibilityTraits;
}

- (UIAccessibilityTraits)scrimAccessibilityTraits {
return _scrimAccessibilityTraits;
}

#pragma mark - MDCSheetContainerViewDelegate

- (void)sheetContainerViewDidHide:(nonnull __unused MDCSheetContainerView *)containerView {
@@ -48,3 +48,36 @@
@property(nonatomic, assign) BOOL dismissOnBackgroundTap;

@end

@interface MDCBottomSheetTransitionController (ScrimAccessibility)

/**
If @c YES, then the dimmed scrim view will act as an accessibility element for dismissing the
bottom sheet.
Defaults to @c NO.
*/
@property(nonatomic, assign) BOOL isScrimAccessibilityElement;

/**
The @c accessibilityLabel value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityLabel;

/**
The @c accessibilityHint value of the dimmed scrim view.
Defaults to @c nil.
*/
@property(nullable, nonatomic, copy) NSString *scrimAccessibilityHint;

/**
The @c accessibilityTraits of the dimmed scrim view.
Defaults to @c UIAccessibilityTraitButton.
*/
@property(nonatomic, assign) UIAccessibilityTraits scrimAccessibilityTraits;

@end
@@ -20,10 +20,23 @@

static const NSTimeInterval MDCBottomSheetTransitionDuration = 0.25;

@implementation MDCBottomSheetTransitionController
@implementation MDCBottomSheetTransitionController {
@protected BOOL _isScrimAccessibilityElement;
@protected NSString *_scrimAccessibilityLabel;
@protected NSString *_scrimAccessibilityHint;
@protected UIAccessibilityTraits _scrimAccessibilityTraits;
}

#pragma mark - UIViewControllerTransitioningDelegate

- (instancetype)init {
self = [super init];
if (self) {
_scrimAccessibilityTraits = UIAccessibilityTraitButton;
}
return self;
}

- (UIPresentationController *)
presentationControllerForPresentedViewController:(UIViewController *)presented
presentingViewController:(UIViewController *)presenting
@@ -33,6 +46,10 @@ @implementation MDCBottomSheetTransitionController
presentingViewController:presenting];
presentationController.trackingScrollView = self.trackingScrollView;
presentationController.dismissOnBackgroundTap = self.dismissOnBackgroundTap;
presentationController.scrimAccessibilityTraits = _scrimAccessibilityTraits;
presentationController.isScrimAccessibilityElement = _isScrimAccessibilityElement;
presentationController.scrimAccessibilityHint = _scrimAccessibilityHint;
presentationController.scrimAccessibilityLabel = _scrimAccessibilityLabel;
return presentationController;
}

@@ -131,4 +148,36 @@ - (CGRect)frameOfPresentedViewController:(UIViewController *)presentedViewContro
}
}

- (void)setIsScrimAccessibilityElement:(BOOL)isScrimAccessibilityElement {
_isScrimAccessibilityElement = isScrimAccessibilityElement;
}

- (BOOL)isScrimAccessibilityElement {
return _isScrimAccessibilityElement;
}

- (void)setScrimAccessibilityLabel:(NSString *)scrimAccessibilityLabel {
_scrimAccessibilityLabel = scrimAccessibilityLabel;
}

- (NSString *)scrimAccessibilityLabel {
return _scrimAccessibilityLabel;
}

- (void)setScrimAccessibilityHint:(NSString *)scrimAccessibilityHint {
_scrimAccessibilityHint = scrimAccessibilityHint;
}

- (NSString *)scrimAccessibilityHint {
return _scrimAccessibilityHint;
}

- (void)setScrimAccessibilityTraits:(UIAccessibilityTraits)scrimAccessibilityTraits {
_scrimAccessibilityTraits = scrimAccessibilityTraits;
}

- (UIAccessibilityTraits)scrimAccessibilityTraits {
return _scrimAccessibilityTraits;
}

@end

0 comments on commit 031d797

Please sign in to comment.
You can’t perform that action at this time.