Skip to content

Commit

Permalink
[ProgressView] Adding default accessibility label
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 301788026
  • Loading branch information
Nobody authored and material-automation committed Mar 19, 2020
1 parent 8fe34d1 commit 58a1813
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 86 deletions.
3 changes: 0 additions & 3 deletions MaterialComponents.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -1216,9 +1216,6 @@ Pod::Spec.new do |mdc|
component.source_files = [
"components/#{component.base_name}/src/*.{h,m}",
]
component.resources = [
"components/#{component.base_name}/src/Material#{component.base_name}.bundle"
]

component.dependency "MDFInternationalization"
component.dependency "MaterialComponents/Palettes"
Expand Down
39 changes: 3 additions & 36 deletions components/ProgressView/src/MDCProgressView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

#include <tgmath.h>

#import "MaterialPalettes.h"
#import "MaterialProgressViewStrings.h"
#import "MaterialProgressViewStrings_table.h"
#import "MaterialMath.h"
#import <MDFInternationalization/MDFInternationalization.h>
#import "MaterialMath.h"
#import "MaterialPalettes.h"

static inline UIColor *MDCProgressViewDefaultTintColor(void) {
return MDCPalette.bluePalette.tint500;
Expand All @@ -31,9 +29,6 @@

static const NSTimeInterval MDCProgressViewAnimationDuration = 0.25;

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

@interface MDCProgressView ()
@property(nonatomic, strong) UIView *progressView;
@property(nonatomic, strong) UIView *trackView;
Expand Down Expand Up @@ -271,35 +266,7 @@ - (void)announceAccessibilityValueChange {
}

- (NSString *)accessibilityLabel {
return self.accessibilityProgressView.accessibilityLabel ?: [self defaultAccessibilityLabel];
}

- (NSString *)defaultAccessibilityLabel {
MaterialProgressViewStringId keyIndex = kStr_MaterialProgressViewAccessibilityLabel;
NSString *key = kMaterialProgressViewStringTable[keyIndex];
return NSLocalizedStringFromTableInBundle(key, kMaterialProgressViewStringsTableName,
[[self class] bundle], @"Progress View");
}

#pragma mark - Resource Bundle

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

return bundle;
}

+ (NSString *)bundlePathWithName:(NSString *)bundleName {
// In iOS 8+, we could be included by way of a dynamic framework, and our resource bundles may
// not be in the main .app bundle, but rather in a nested framework, so figure out where we live
// and use that as the search location.
NSBundle *bundle = [NSBundle bundleForClass:[MDCProgressView class]];
NSString *resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath];
return [resourcePath stringByAppendingPathComponent:bundleName];
return self.accessibilityProgressView.accessibilityLabel;
}

#pragma mark Private
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions components/ProgressView/src/private/MaterialProgressViewStrings.h

This file was deleted.

This file was deleted.

13 changes: 3 additions & 10 deletions components/ProgressView/tests/unit/ProgressViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@

#import "MaterialProgressView.h"

@interface MDCProgressView (ProgressViewTests)

- (NSString *)defaultAccessibilityLabel;

@end

@interface ProgressViewTests : XCTestCase

@end

@implementation ProgressViewTests {
Expand Down Expand Up @@ -95,15 +90,13 @@ - (void)testTraitCollectionDidChangeBlockCalledWithExpectedParameters {
XCTAssertEqual(passedTraitCollection, fakeTraitCollection);
}

- (void)testAccessibilityLabelHasCorrectValueSet {
- (void)testAccessibilityLabelMatchesUIProgressView {
// Given
UIProgressView *uiProgressView = [[UIProgressView alloc] init];
MDCProgressView *mdcProgressView = [[MDCProgressView alloc] init];
NSString *expectedAccessibilityLabel =
uiProgressView.accessibilityLabel ?: [mdcProgressView defaultAccessibilityLabel];

// Then
XCTAssertEqual(mdcProgressView.accessibilityLabel, expectedAccessibilityLabel);
XCTAssertEqual(uiProgressView.accessibilityLabel, mdcProgressView.accessibilityLabel);
}

@end

0 comments on commit 58a1813

Please sign in to comment.