Adding pager, scrollview, viewgroup, webview, drawer roles (#34477)

Summary:
- adds missing roles
- adds custom roles that don't exist in TalkBack (see the [compositor.json][10] and [string.xml][11] files).
- fixes [issues with Drawer][12]
- fixes issues with ScrollView missing roles
- seek control already exist as adjustable https://github.com/facebook/react-native/pull/34477/commits/d460d097ac0f5df8002e072711023517905f9ca9

Relevant https://github.com/facebook/react-native/issues/30839#issuecomment-1222293556
fixes https://github.com/facebook/react-native/issues/30839

## Changelog

[Android] [Fixed]  - Adding pager, scrollview, viewgroup, webview, drawer roles

Pull Request resolved: https://github.com/facebook/react-native/pull/34477

Test Plan:
Android
- Drawer Layout and ScrollView (02/09/22) https://github.com/facebook/react-native/pull/34477#issuecomment-1235293165
- sliding drawer, drawer layout, icon menu https://github.com/facebook/react-native/pull/34477#issuecomment-1224112650
- Horizontal and Vertical ScrollView https://github.com/facebook/react-native/pull/34477#issuecomment-1225478289
- Toast https://github.com/facebook/react-native/pull/34477#issuecomment-1225369629
- CheckedTextView https://github.com/facebook/react-native/pull/34477#discussion_r959329833
- Spinner (dropdownlist) https://github.com/facebook/react-native/pull/34477#discussion_r959374894
- EditText https://github.com/facebook/react-native/pull/34477#discussion_r959412185
- WebView https://github.com/facebook/react-native/pull/34477#discussion_r959417518
- Testing chime_up and chime_down sound feedback in Scrollable https://github.com/facebook/react-native/pull/34477#issuecomment-1238882030

iOS https://github.com/facebook/react-native/pull/34477#issuecomment-1232418595

[10]: https://github.com/google/talkback/blob/771de7cdbf55b6adb4ca4c64c27a52584f2337cc/compositor/src/main/res/raw/compositor.json#L1082-L1108
[11]: https://github.com/google/talkback/blob/771de7cdbf55b6adb4ca4c64c27a52584f2337cc/compositor/src/main/res/values/strings.xml#L223
[12]: https://github.com/facebook/react-native/pull/34477#issuecomment-1224112650

Reviewed By: NickGerleman

Differential Revision: D39894307

Pulled By: blavalla

fbshipit-source-id: 4a8da78bae485ead0523689631d88d1031a07b74
This commit is contained in:
fabriziobertoglio1987 authored and Facebook GitHub Bot committed 2022-11-07 23:25:33 -08:00
1 parent 78aabd29ca
commit 55c0df43b9
9 files changed
+357 -106

No files matched your search

@@ -96,6 +96,7 @@ public class ReactAccessibilityDelegate extends ExploreByTouchHelper {
public enum AccessibilityRole {
NONE,
BUTTON,
DROPDOWNLIST,
TOGGLEBUTTON,
LINK,
SEARCH,
@@ -123,12 +124,22 @@ public class ReactAccessibilityDelegate extends ExploreByTouchHelper {
TIMER,
LIST,
GRID,
PAGER,
SCROLLVIEW,
HORIZONTALSCROLLVIEW,
VIEWGROUP,
WEBVIEW,
DRAWERLAYOUT,
SLIDINGDRAWER,
ICONMENU,
TOOLBAR;
public static String getValue(AccessibilityRole role) {
switch (role) {
case BUTTON:
return "android.widget.Button";
case DROPDOWNLIST:
return "android.widget.Spinner";
case TOGGLEBUTTON:
return "android.widget.ToggleButton";
case SEARCH:
@@ -136,7 +147,7 @@ public class ReactAccessibilityDelegate extends ExploreByTouchHelper {
case IMAGE:
return "android.widget.ImageView";
case IMAGEBUTTON:
return "android.widget.ImageButon";
return "android.widget.ImageButton";
case KEYBOARDKEY:
return "android.inputmethodservice.Keyboard$Key";
case TEXT:
@@ -155,6 +166,22 @@ public class ReactAccessibilityDelegate extends ExploreByTouchHelper {
return "android.widget.AbsListView";
case GRID:
return "android.widget.GridView";
case SCROLLVIEW:
return "android.widget.ScrollView";
case HORIZONTALSCROLLVIEW:
return "android.widget.HorizontalScrollView";
case PAGER:
return "androidx.viewpager.widget.ViewPager";
case DRAWERLAYOUT:
return "androidx.drawerlayout.widget.DrawerLayout";
case SLIDINGDRAWER:
return "android.widget.SlidingDrawer";
case ICONMENU:
return "com.android.internal.view.menu.IconMenuView";
case VIEWGROUP:
return "android.view.ViewGroup";
case WEBVIEW:
return "android.webkit.WebView";
case NONE:
case LINK:
case SUMMARY:
@@ -29,5 +29,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/views/scroll:scroll"),
react_native_root_target(":generated_components_java-FBReactNativeComponentSpec"),
react_native_target("res:uimanager"),
],
)
@@ -10,10 +10,16 @@ package com.facebook.react.views.drawer;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.facebook.common.logging.FLog;
import com.facebook.react.R;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole;
import com.facebook.react.uimanager.events.NativeGestureUtil;
/**
@@ -29,6 +35,30 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
public ReactDrawerLayout(ReactContext reactContext) {
super(reactContext);
ViewCompat.setAccessibilityDelegate(
this,
new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
final AccessibilityRole accessibilityRole =
(AccessibilityRole) host.getTag(R.id.accessibility_role);
if (accessibilityRole != null) {
info.setClassName(AccessibilityRole.getValue(accessibilityRole));
}
}
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
final AccessibilityRole accessibilityRole =
(AccessibilityRole) host.getTag(R.id.accessibility_role);
if (accessibilityRole != null) {
event.setClassName(AccessibilityRole.getValue(accessibilityRole));
}
}
});
}
@Override