Skip to content

Commit

Permalink
added android functionality for currentViewStates
Browse files Browse the repository at this point in the history
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
Ziqi Chen authored and facebook-github-bot committed Jul 17, 2018
1 parent edf7100 commit c1d0ccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
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
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit c1d0ccd

Please sign in to comment.