Skip to content

Commit

Permalink
[ActionSheet] Add alert anouncement for voiceover users.
Browse files Browse the repository at this point in the history
Similarly to how UIActionSheet announces "Alert" for voiceover users, we imitate the behavior here for MDCActionSheetController.

PiperOrigin-RevId: 316851432
  • Loading branch information
yarneo authored and material-automation committed Jun 17, 2020
1 parent f425b89 commit b98382a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
29 changes: 29 additions & 0 deletions components/ActionSheet/src/MDCActionSheetController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import "private/MDCActionSheetHeaderView.h"
#import "private/MDCActionSheetItemTableViewCell.h"
#import "private/MaterialActionSheetStrings.h"
#import "private/MaterialActionSheetStrings_table.h"
#import "MDCActionSheetControllerDelegate.h"
#import "MaterialAvailability.h"
#import "MaterialShadowElevations.h"
Expand All @@ -27,6 +29,9 @@
static const CGFloat kActionTextAlpha = (CGFloat)0.87;
static const CGFloat kDividerDefaultAlpha = (CGFloat)0.12;

// The Bundle for string resources.
static NSString *const kMaterialActionSheetBundle = @"MaterialActionSheet.bundle";

@interface MDCActionSheetController () <MDCBottomSheetPresentationControllerDelegate,
UITableViewDelegate,
UITableViewDataSource>
Expand Down Expand Up @@ -203,6 +208,12 @@ - (void)viewDidLoad {
[self.view addSubview:self.tableView];
[self.view addSubview:self.header];
[self.view addSubview:self.headerDividerView];

NSString *key =
kMaterialActionSheetStringTable[kStr_MaterialActionSheetPresentedAccessibilityAnnouncement];
NSString *announcement = NSLocalizedStringFromTableInBundle(
key, kMaterialActionSheetStringsTableName, [[self class] bundle], @"Alert");
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, announcement);
}

- (void)viewDidLayoutSubviews {
Expand Down Expand Up @@ -590,4 +601,22 @@ - (void)bottomSheetPresentationControllerDismissalAnimationCompleted:
}
}

#pragma mark - Resource bundle

+ (NSBundle *)bundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
bundle = [NSBundle bundleWithPath:[self bundlePathWithName:kMaterialActionSheetBundle]];
});

return bundle;
}

+ (NSString *)bundlePathWithName:(NSString *)bundleName {
NSBundle *bundle = [NSBundle bundleForClass:[MDCActionSheetController class]];
NSString *resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath];
return [resourcePath stringByAppendingPathComponent:bundleName];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Accessibility announcement when an action sheet is displayed. */
"MaterialActionSheetPresentedAccessibilityAnnouncement" = "Alert";
23 changes: 23 additions & 0 deletions components/ActionSheet/src/private/MaterialActionSheetStrings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020-present the Material Components for iOS authors. All Rights
// Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// GENERATED CODE: DO NOT EDIT BY HAND
// GENERATED FROM:
// components/ActionSheet/src/MaterialActionSheet.bundle/Resources/en.lproj/MaterialActionSheet.strings
// GENERATED BY: generate_string_tables.py

typedef enum {
kStr_MaterialActionSheetPresentedAccessibilityAnnouncement = 0,
} MaterialActionSheetStringId;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// GENERATED CODE: DO NOT EDIT BY HAND
// GENERATED FROM:
// components/ActionSheet/src/MaterialActionSheet.bundle/Resources/en.lproj/MaterialActionSheet.strings
// GENERATED BY: generate_string_tables.py

#import <Foundation/Foundation.h>

// A table of string keys to look-up localized strings in the bundle.
// This table is to be indexed using the generated enum.

static NSString *const kMaterialActionSheetStringTable[] = {
@"MaterialActionSheetPresentedAccessibilityAnnouncement", // Alert
};
#define kNumMaterialActionSheetStrings 1
#define kMaterialActionSheetStringsOffset 0
#define kMaterialActionSheetStringsEnd 10000
static NSString *const kMaterialActionSheetStringsTableName = @"MaterialActionSheet";

0 comments on commit b98382a

Please sign in to comment.