Skip to content

Commit

Permalink
fix:无障碍修复 (alibaba#3289)
Browse files Browse the repository at this point in the history
  • Loading branch information
katherine95s authored May 5, 2022
1 parent a66e061 commit 1aabf04
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public interface Name {
String ARIA_LABEL = "ariaLabel";
String ARIA_HIDDEN = "ariaHidden";
String ROLE = "role";
String ACCESSIBLE = "accessible";

String LAYERLIMIT = "layerLimit";
String LAYER_LIMIT = "layer-limit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.apache.weex.ui.component;

import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
Expand Down Expand Up @@ -855,6 +858,10 @@ protected boolean setProperty(String key, Object param) {
String label = WXUtils.getString(param, "");
setAriaLabel(label);
return true;
case Constants.Name.ACCESSIBLE:
boolean accessible = WXUtils.getBoolean(param, false);
setAccessible(accessible);
return true;
case Constants.Name.ARIA_HIDDEN:
boolean isHidden = WXUtils.getBoolean(param, false);
setAriaHidden(isHidden);
Expand Down Expand Up @@ -1308,7 +1315,7 @@ protected MeasureOutput measure(int width, int height) {
protected void setAriaHidden(boolean isHidden) {
View host = getHostView();
if (host != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
host.setImportantForAccessibility(isHidden ? View.IMPORTANT_FOR_ACCESSIBILITY_NO : View.IMPORTANT_FOR_ACCESSIBILITY_YES);
host.setImportantForAccessibility(isHidden ? IMPORTANT_FOR_ACCESSIBILITY_NO : IMPORTANT_FOR_ACCESSIBILITY_YES);
}
}

Expand All @@ -1319,6 +1326,18 @@ protected void setAriaLabel(String label) {
}
}

protected void setAccessible(Boolean accessible) {
View host = getHostView();
if (host != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (accessible) {
getHostView().setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
} else {
getHostView().setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
}
}
}


protected void setRole(String roleKey) {
View host = getHostView();
String role = roleKey;
Expand Down Expand Up @@ -1464,7 +1483,7 @@ protected void createViewImpl() {
if(mHost.getId() == View.NO_ID)
mHost.setId(WXViewUtils.generateViewId());
if(TextUtils.isEmpty(mHost.getContentDescription()) && WXEnvironment.isApkDebugable()){
mHost.setContentDescription(getRef());
// mHost.setContentDescription(getRef());
}
ComponentObserver observer;
if ((observer = getInstance().getComponentObserver()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package org.apache.weex.ui.component;

import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.util.Pair;
Expand Down Expand Up @@ -197,6 +200,9 @@ public void createViewImpl() {
}
if (getHostView() != null) {
getHostView().setClipToPadding(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
getHostView().setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
}
}
}

Expand Down

0 comments on commit 1aabf04

Please sign in to comment.