Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[_ASPendingState] Make sure accessibility strings are not nil before allocating attributed strings for them #trivial #581

Merged
merged 2 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ - (void)setAccessibilityLabel:(NSString *)accessibilityLabel
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityLabel, accessibilityLabel, accessibilityLabel, accessibilityLabel);
if (AS_AT_LEAST_IOS11) {
NSAttributedString *accessibilityAttributedLabel = [[NSAttributedString alloc] initWithString:accessibilityLabel];
NSAttributedString *accessibilityAttributedLabel = accessibilityLabel ? [[NSAttributedString alloc] initWithString:accessibilityLabel] : nil;
_setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedLabel, accessibilityAttributedLabel, @"accessibilityAttributedLabel", accessibilityAttributedLabel);
}
}
Expand Down Expand Up @@ -972,7 +972,7 @@ - (void)setAccessibilityHint:(NSString *)accessibilityHint
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityHint, accessibilityHint, accessibilityHint, accessibilityHint);
if (AS_AT_LEAST_IOS11) {
NSAttributedString *accessibilityAttributedHint = [[NSAttributedString alloc] initWithString:accessibilityHint];
NSAttributedString *accessibilityAttributedHint = accessibilityHint ? [[NSAttributedString alloc] initWithString:accessibilityHint] : nil;
_setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedHint, accessibilityAttributedHint, @"accessibilityAttributedHint", accessibilityAttributedHint);
}
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ - (void)setAccessibilityValue:(NSString *)accessibilityValue
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityValue, accessibilityValue, accessibilityValue, accessibilityValue);
if (AS_AT_LEAST_IOS11) {
NSAttributedString *accessibilityAttributedValue = [[NSAttributedString alloc] initWithString:accessibilityValue];
NSAttributedString *accessibilityAttributedValue = accessibilityValue ? [[NSAttributedString alloc] initWithString:accessibilityValue] : nil;
_setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedValue, accessibilityAttributedValue, @"accessibilityAttributedValue", accessibilityAttributedValue);
}
}
Expand Down
39 changes: 20 additions & 19 deletions Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#import <AsyncDisplayKit/_ASCoreAnimationExtras.h>
#import <AsyncDisplayKit/_ASAsyncTransactionContainer.h>
#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASEqualityHelpers.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>

#define __shouldSetNeedsDisplay(layer) (flags.needsDisplay \
|| (flags.setOpaque && opaque != (layer).opaque)\
Expand Down Expand Up @@ -595,11 +596,11 @@ - (NSString *)accessibilityLabel

- (void)setAccessibilityLabel:(NSString *)newAccessibilityLabel
{
if (![accessibilityLabel isEqualToString:newAccessibilityLabel]) {
if (! ASObjectIsEqual(accessibilityLabel, newAccessibilityLabel)) {
_flags.setAccessibilityLabel = YES;
_flags.setAccessibilityAttributedLabel = YES;
accessibilityLabel = [newAccessibilityLabel copy];
accessibilityAttributedLabel = [[NSAttributedString alloc] initWithString:newAccessibilityLabel];
accessibilityLabel = newAccessibilityLabel ? [newAccessibilityLabel copy] : nil;
accessibilityAttributedLabel = newAccessibilityLabel ? [[NSAttributedString alloc] initWithString:newAccessibilityLabel] : nil;
}
}

Expand All @@ -610,11 +611,11 @@ - (NSAttributedString *)accessibilityAttributedLabel

- (void)setAccessibilityAttributedLabel:(NSAttributedString *)newAccessibilityAttributedLabel
{
if (![accessibilityAttributedLabel isEqualToAttributedString: newAccessibilityAttributedLabel]) {
if (! ASObjectIsEqual(accessibilityAttributedLabel, newAccessibilityAttributedLabel)) {
_flags.setAccessibilityAttributedLabel = YES;
_flags.setAccessibilityLabel = YES;
accessibilityAttributedLabel = [newAccessibilityAttributedLabel copy];
accessibilityLabel = [newAccessibilityAttributedLabel.string copy];
accessibilityAttributedLabel = newAccessibilityAttributedLabel ? [newAccessibilityAttributedLabel copy] : nil;
accessibilityLabel = newAccessibilityAttributedLabel ? [newAccessibilityAttributedLabel.string copy] : nil;
}
}

Expand All @@ -625,11 +626,11 @@ - (NSString *)accessibilityHint

- (void)setAccessibilityHint:(NSString *)newAccessibilityHint
{
if (![accessibilityHint isEqualToString:newAccessibilityHint]) {
if (! ASObjectIsEqual(accessibilityHint, newAccessibilityHint)) {
_flags.setAccessibilityHint = YES;
_flags.setAccessibilityAttributedHint = YES;
accessibilityHint = [newAccessibilityHint copy];
accessibilityAttributedHint = [[NSAttributedString alloc] initWithString:newAccessibilityHint];
accessibilityHint = newAccessibilityHint ? [newAccessibilityHint copy] : nil;
accessibilityAttributedHint = newAccessibilityHint ? [[NSAttributedString alloc] initWithString:newAccessibilityHint] : nil;
}
}

Expand All @@ -640,11 +641,11 @@ - (NSAttributedString *)accessibilityAttributedHint

- (void)setAccessibilityAttributedHint:(NSAttributedString *)newAccessibilityAttributedHint
{
if (![accessibilityAttributedHint isEqual:newAccessibilityAttributedHint]) {
if (! ASObjectIsEqual(accessibilityAttributedHint, newAccessibilityAttributedHint)) {
_flags.setAccessibilityAttributedHint = YES;
_flags.setAccessibilityHint = YES;
accessibilityAttributedHint = [newAccessibilityAttributedHint copy];
accessibilityHint = [newAccessibilityAttributedHint.string copy];
accessibilityAttributedHint = newAccessibilityAttributedHint ? [newAccessibilityAttributedHint copy] : nil;
accessibilityHint = newAccessibilityAttributedHint ? [newAccessibilityAttributedHint.string copy] : nil;
}
}

Expand All @@ -655,11 +656,11 @@ - (NSString *)accessibilityValue

- (void)setAccessibilityValue:(NSString *)newAccessibilityValue
{
if (![accessibilityValue isEqualToString:newAccessibilityValue]) {
if (! ASObjectIsEqual(accessibilityValue, newAccessibilityValue)) {
_flags.setAccessibilityValue = YES;
_flags.setAccessibilityAttributedValue = YES;
accessibilityValue = [newAccessibilityValue copy];
accessibilityAttributedValue = [[NSAttributedString alloc] initWithString:newAccessibilityValue];
accessibilityValue = newAccessibilityValue ? [newAccessibilityValue copy] : nil;
accessibilityAttributedValue = newAccessibilityValue ? [[NSAttributedString alloc] initWithString:newAccessibilityValue] : nil;
}
}

Expand All @@ -670,11 +671,11 @@ - (NSAttributedString *)accessibilityAttributedValue

- (void)setAccessibilityAttributedValue:(NSAttributedString *)newAccessibilityAttributedValue
{
if (![accessibilityAttributedValue isEqualToAttributedString:newAccessibilityAttributedValue]) {
if (! ASObjectIsEqual(accessibilityAttributedValue, newAccessibilityAttributedValue)) {
_flags.setAccessibilityAttributedValue = YES;
_flags.setAccessibilityValue = YES;
accessibilityAttributedValue = [newAccessibilityAttributedValue copy];
accessibilityValue = [newAccessibilityAttributedValue.string copy];
accessibilityAttributedValue = newAccessibilityAttributedValue? [newAccessibilityAttributedValue copy] : nil;
accessibilityValue = newAccessibilityAttributedValue ? [newAccessibilityAttributedValue.string copy] : nil;
}
}

Expand Down
16 changes: 13 additions & 3 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,19 @@ - (void)checkSimpleBridgePropertiesSetPropagate:(BOOL)isLayerBacked
node.debugName = @"quack like a duck";

node.isAccessibilityElement = YES;
node.accessibilityLabel = @"Ship love";
node.accessibilityHint = @"Awesome things will happen";
node.accessibilityValue = @"1 of 2";

for (int i = 0; i < 4; i++) {
if (i % 2 == 0) {
XCTAssertNoThrow(node.accessibilityLabel = nil);
XCTAssertNoThrow(node.accessibilityHint = nil);
XCTAssertNoThrow(node.accessibilityValue = nil);
} else {
node.accessibilityLabel = @"Ship love";
node.accessibilityHint = @"Awesome things will happen";
node.accessibilityValue = @"1 of 2";
}
}

node.accessibilityTraits = UIAccessibilityTraitSelected | UIAccessibilityTraitButton;
node.accessibilityFrame = CGRectMake(1, 2, 3, 4);
node.accessibilityLanguage = @"mas";
Expand Down