From 6fbc2c99727b86f674de32481ed574a820376236 Mon Sep 17 00:00:00 2001 From: Adam Comella Date: Wed, 22 Feb 2017 11:00:38 -0800 Subject: [PATCH] iOS: Remove leading space from accessibilityLabel Summary: 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: ``` ``` 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. Adam Closes https://github.com/facebook/react-native/pull/12269 Reviewed By: javache Differential Revision: D4596761 Pulled By: shergin fbshipit-source-id: 7d5ff704e858d9f277d1547339a2831ffa90f592 --- React/Views/RCTView.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 21d7a71bccde79..39ec4f971751ea 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -81,11 +81,17 @@ - (UIView *)react_findClipView static NSString *RCTRecursiveAccessibilityLabel(UIView *view) { + BOOL isFirstIteration = YES; NSMutableString *str = [NSMutableString stringWithString:@""]; for (UIView *subview in view.subviews) { + if (isFirstIteration) { + isFirstIteration = NO; + } else { + [str appendString:@" "]; + } + NSString *label = subview.accessibilityLabel; if (label) { - [str appendString:@" "]; [str appendString:label]; } else { [str appendString:RCTRecursiveAccessibilityLabel(subview)];