Skip to content

Commit

Permalink
Fix addition of comma at the end of accessibility labels on Android. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmulcahy authored and cpojer committed Aug 7, 2019
1 parent ffdf3f2 commit 812abfd
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
package com.facebook.react.uimanager;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewParent;
import androidx.core.view.ViewCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray;
Expand Down Expand Up @@ -173,23 +176,23 @@ private void updateViewContentDescription(@Nonnull T view) {
final String accessibilityLabel = (String) view.getTag(R.id.accessibility_label);
final ReadableArray accessibilityStates = (ReadableArray) view.getTag(R.id.accessibility_states);
final String accessibilityHint = (String) view.getTag(R.id.accessibility_hint);
StringBuilder contentDescription = new StringBuilder();
final List<String> contentDescription = new ArrayList<>();
if (accessibilityLabel != null) {
contentDescription.append(accessibilityLabel + ", ");
contentDescription.add(accessibilityLabel);
}
if (accessibilityStates != null) {
for (int i = 0; i < accessibilityStates.size(); i++) {
String state = accessibilityStates.getString(i);
if (sStateDescription.containsKey(state)) {
contentDescription.append(view.getContext().getString(sStateDescription.get(state)) + ", ");
contentDescription.add(view.getContext().getString(sStateDescription.get(state)));
}
}
}
if (accessibilityHint != null) {
contentDescription.append(accessibilityHint + ", ");
contentDescription.add(accessibilityHint);
}
if (contentDescription.length() > 0) {
view.setContentDescription(contentDescription.toString());
if (contentDescription.size() > 0) {
view.setContentDescription(TextUtils.join(", ", contentDescription));
}
}

Expand Down

0 comments on commit 812abfd

Please sign in to comment.