Skip to content

Commit

Permalink
iOS: Remove leading space from accessibilityLabel
Browse files Browse the repository at this point in the history
In some cases, the accessibilityLabel contains a leading space. This is because `RCTRecursiveAccessibilityLabel` adds a space before every iteration of the loop including the first.

After this change, the contract is that:
  - `RCTRecursiveAccessibilityLabel` always returns a string with a leading space.
  - `accessibilityLabel` never returns a string with a leading space.

**Test plan**

I created a test app with the following code:

```
<View style={{height: 100, width: 100, backgroundColor: 'steelblue'}} accessible={true}>
  <View style={{height: 20, width: 20, backgroundColor: 'red'}} accessibilityLabel='One' />
  <View style={{height: 20, width: 20, backgroundColor: 'yellow'}} accessibilityLabel='Two' />
  <View style={{height: 20, width: 20, backgroundColor: 'green'}} accessibilityLabel='Three' />
</View>
```

Before this change, the accessibilityLabel of the outermost View was " One Two Three" (notice the leading space).

After this change, it is "One Two Three" as desired.
  • Loading branch information
Adam Comella committed Feb 11, 2017
1 parent 6f2544a commit 3c1c8cc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ - (NSString *)accessibilityLabel
if (super.accessibilityLabel) {
return super.accessibilityLabel;
}
return RCTRecursiveAccessibilityLabel(self);
NSString *str = RCTRecursiveAccessibilityLabel(self);
return [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}

- (void)setPointerEvents:(RCTPointerEvents)pointerEvents
Expand Down

0 comments on commit 3c1c8cc

Please sign in to comment.