Permalink
Browse files

added android functionality for currentViewStates

Summary:
Added native android support for the prop accessibilityStates.

If 'selected' is passed in, it calls view.setSelected(true)
If 'disabled' is passed in, it calls view.setEnabled(false)

If both are passed in, both are set on the view.

Reviewed By: blavalla

Differential Revision: D8838407

fbshipit-source-id: a942dabcdc5d9e35f0316465e97317739a8b4b25
  • Loading branch information...
ziqichen6 authored and facebook-github-bot committed Jul 17, 2018
1 parent edf7100 commit c1d0ccde0f6f8615fce077ef7ee0867a14ca0fb7
@@ -12,6 +12,7 @@
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import com.facebook.react.bridge.ReadableArray;
import javax.annotation.Nullable;
/**
@@ -102,7 +103,7 @@ public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final Accessibi
}
/**
* Variables and methods for setting accessibilityRole on view properties.
* Method for setting accessibilityRole on view properties.
*/
public static void updateAccessibilityRole(View view, String role) {
if (role == null) {
@@ -30,6 +30,7 @@
private static final String PROP_ACCESSIBILITY_COMPONENT_TYPE = "accessibilityComponentType";
private static final String PROP_ACCESSIBILITY_LIVE_REGION = "accessibilityLiveRegion";
private static final String PROP_ACCESSIBILITY_ROLE = "accessibilityRole";
private static final String PROP_CURRENT_VIEW_STATES = "currentViewStates";
private static final String PROP_IMPORTANT_FOR_ACCESSIBILITY = "importantForAccessibility";
// DEPRECATED
@@ -123,6 +124,20 @@ public void setAccessibilityRole(T view, String accessibilityRole) {
AccessibilityRoleUtil.updateAccessibilityRole(view, accessibilityRole);
}
@ReactProp(name = PROP_CURRENT_VIEW_STATES)
public void setViewStates(T view, ReadableArray currentViewStates) {
view.setSelected(false);
view.setEnabled(true);
for (int i = 0; i < currentViewStates.size(); i++) {
String state = currentViewStates.getString(i);
if (state.equals("selected")) {
view.setSelected(true);
} else if (state.equals("disabled")) {
view.setEnabled(false);
}
}
}
@ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY)
public void setImportantForAccessibility(T view, String importantForAccessibility) {
if (importantForAccessibility == null || importantForAccessibility.equals("auto")) {

0 comments on commit c1d0ccd

Please sign in to comment.