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

iOS: Remove leading space from accessibilityLabel #12269

Closed

Conversation

rigdern
Copy link
Contributor

@rigdern rigdern commented Feb 7, 2017

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.

This change fixes it by avoiding adding a space on the first iteration of the loop.

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.

Adam Comella
Microsoft Corp.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 7, 2017
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.
@rigdern rigdern force-pushed the rigdern/iosAccessibilityLabel branch from 43761d7 to 3c1c8cc Compare February 11, 2017 00:55
@shergin
Copy link
Contributor

shergin commented Feb 21, 2017

I believe, it would be better if we will fix it inside RCTRecursiveAccessibilityLabel.

Adam Comella added 2 commits February 21, 2017 17:25
This reverts commit 3c1c8cc.

Implementing a different solution.
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.

This change fixes it by avoiding adding a space on the first iteration of the loop.
@rigdern
Copy link
Contributor Author

rigdern commented Feb 22, 2017

@shergin Thanks for the feedback. I pushed a commit which does the fix inside of RCTRecursiveAccessibilityLabel instead.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Feb 22, 2017
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added Import Failed and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 22, 2017
@facebook-github-bot
Copy link
Contributor

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

GaborWnuk pushed a commit to GaborWnuk/react-native that referenced this pull request Feb 28, 2017
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:

```
<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.

Adam
Closes facebook#12269

Reviewed By: javache

Differential Revision: D4596761

Pulled By: shergin

fbshipit-source-id: 7d5ff704e858d9f277d1547339a2831ffa90f592
dudeinthemirror pushed a commit to dudeinthemirror/react-native that referenced this pull request Mar 1, 2017
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:

```
<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.

Adam
Closes facebook#12269

Reviewed By: javache

Differential Revision: D4596761

Pulled By: shergin

fbshipit-source-id: 7d5ff704e858d9f277d1547339a2831ffa90f592
dudeinthemirror pushed a commit to dudeinthemirror/react-native that referenced this pull request Mar 1, 2017
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:

```
<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.

Adam
Closes facebook#12269

Reviewed By: javache

Differential Revision: D4596761

Pulled By: shergin

fbshipit-source-id: 7d5ff704e858d9f277d1547339a2831ffa90f592
@rigdern rigdern deleted the rigdern/iosAccessibilityLabel branch March 1, 2017 22:31
@jaunesarmiento
Copy link

I'm not sure if it's just my setup but I'm still getting whitespaces in my accessibility labels even after applying this patch. Probably due to higher-order components (e.g Redux's connect). I really need this to work for our UI tests.

Here's a sample output that XCUIApplication().otherElements prints in the log:

    Other 0x600000361800: traits: 8589934592, {{-331.3, 44.0}, {331.3, 158.0}}, label: ' ',
    Other 0x600000362400: traits: 8589934592, {{-331.3, 202.0}, {331.3, 50.0}}, label: 'Game Feed',
    Other 0x6000003624c0: traits: 8589934592, {{-331.3, 202.0}, {331.3, 50.0}}, label: 'Game Feed',
    Other 0x600000362640: traits: 8589934592, {{-331.3, 252.0}, {331.3, 50.0}}, label: 'My Games',
    Other 0x600000362700: traits: 8589934592, {{-331.3, 252.0}, {331.3, 50.0}}, label: 'My Games',
    Other 0x600000362880: traits: 8589934592, {{-331.3, 302.0}, {331.3, 50.0}}, label: 'Preferred Sports',
    Other 0x600000362940: traits: 8589934592, {{-331.3, 302.0}, {331.3, 50.0}}, label: 'Preferred Sports',
    Other 0x600000362c40: traits: 8589934592, {{-331.3, 352.0}, {331.3, 50.0}}, label: 'Profile',
    Other 0x600000362ac0: traits: 8589934592, {{-331.3, 352.0}, {331.3, 50.0}}, label: 'Profile',
    Other 0x600000362dc0: traits: 8589934592, {{-331.3, 402.0}, {331.3, 50.0}}, label: 'Settings',
    Other 0x600000362e80: traits: 8589934592, {{-331.3, 402.0}, {331.3, 50.0}}, label: 'Settings',
    Other 0x600000361c80: traits: 8589934592, {{-331.3, 44.0}, {331.3, 408.0}}, label: '  Game Feed My Games Preferred Sports Profile Settings',
    Other 0x600000361e00: traits: 8589934592, {{-331.3, 44.0}, {331.3, 661.7}}, label: '  Game Feed My Games Preferred Sports Profile Settings  ',
    Other 0x600000361980: traits: 8589934592, {{-331.3, 0.0}, {331.3, 736.0}}, label: '  Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev',
    Other 0x600000363000: traits: 8589934592, {{-331.3, 0.0}, {331.3, 736.0}},
    Other 0x600000361b00: traits: 8589934592, {{-331.3, 0.0}, {331.3, 736.0}}, label: '  Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev ',
    Other 0x600000362580: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}},
    Other 0x600000363780: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '  ',
    Other 0x600000363840: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '  ',
    Other 0x600000363900: traits: 8589934592, {{-414.0, 0.0}, {1656.0, 736.0}}, label: '  ',
    Other 0x600000362280: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '  ',
    Other 0x600000363540: traits: 8589934592, {{182.0, 639.0}, {8.0, 8.0}},
    Other 0x600000363480: traits: 8589934592, {{196.0, 639.0}, {8.0, 8.0}},
    Other 0x6000003633c0: traits: 8589934592, {{210.0, 639.0}, {8.0, 8.0}},
    Other 0x600000363240: traits: 8589934592, {{224.0, 639.0}, {8.0, 8.0}},
    Other 0x600000363600: traits: 8589934592, {{0.0, 636.0}, {414.0, 75.0}}, label: '   ',
    Other 0x600000363180: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '      ',
    Other 0x6000003627c0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '        ',
    Other 0x600000362a00: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '        ',
    Other 0x600000362b80: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '        ',
    Other 0x600000362d00: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '        ',
    Other 0x600000362100: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}},
    Other 0x600000362f40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '         ',
    Other 0x600000361a40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '            Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev ',
    Other 0x600000361ec0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '             Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev  ',
    Other 0x600000361d40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '             Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev  ',
    Other 0x600000361bc0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '             Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev   ',
    Other 0x6000003621c0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}, label: '             Game Feed My Games Preferred Sports Profile Settings   2.5.0.17041001_dev   ',
    Other 0x60000017be40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}},
    Other 0x60000017c080: {{0.0, 0.0}, {414.0, 20.0}},
    Other 0x600000360900: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}},
    Other 0x600000360840: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID,
    Other 0x600000360780: traits: 8389120, {{185.0, 0.0}, {48.0, 20.0}}, label: '5:21 AM',
    Other 0x6000003606c0: traits: 8388608, {{376.0, 0.0}, {33.0, 20.0}}, label: '-100% battery power',
    Other 0x60000017b300: {{0.0, 0.0}, {414.0, 20.0}}

Could it be that the some components return blank as accessiblityLabel?

@rigdern
Copy link
Contributor Author

rigdern commented May 2, 2017

@jaunesarmiento What version of React Native are you using? Are you sure it includes the fix?

@jaunesarmiento
Copy link

@rigdern 0.42. I've used the commit as a patch. Yes, the fix is included cause the prior to this fix, the following have leading whitespace in them:

Other 0x600000362400: traits: 8589934592, {{-331.3, 202.0}, {331.3, 50.0}}, label: 'Game Feed',
Other 0x6000003624c0: traits: 8589934592, {{-331.3, 202.0}, {331.3, 50.0}}, label: 'Game Feed',
Other 0x600000362640: traits: 8589934592, {{-331.3, 252.0}, {331.3, 50.0}}, label: 'My Games',
Other 0x600000362700: traits: 8589934592, {{-331.3, 252.0}, {331.3, 50.0}}, label: 'My Games',
Other 0x600000362880: traits: 8589934592, {{-331.3, 302.0}, {331.3, 50.0}}, label: 'Preferred Sports',
Other 0x600000362940: traits: 8589934592, {{-331.3, 302.0}, {331.3, 50.0}}, label: 'Preferred Sports',
Other 0x600000362c40: traits: 8589934592, {{-331.3, 352.0}, {331.3, 50.0}}, label: 'Profile',
Other 0x600000362ac0: traits: 8589934592, {{-331.3, 352.0}, {331.3, 50.0}}, label: 'Profile',
Other 0x600000362dc0: traits: 8589934592, {{-331.3, 402.0}, {331.3, 50.0}}, label: 'Settings',
Other 0x600000362e80: traits: 8589934592, {{-331.3, 402.0}, {331.3, 50.0}}, label: 'Settings',

@jaunesarmiento
Copy link

@rigdern nevermind. Found out that it's easier to use testID for this use case. Thanks though.

@shergin
Copy link
Contributor

shergin commented May 2, 2017

@jaunesarmiento Obviously, you should not use testID for accessibility purposes! :(

@rigdern
Copy link
Contributor Author

rigdern commented May 25, 2017

@jaunesarmiento I know you may not be interested anymore but I suspect PR #14177 will fix your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants