Fix crash when accessibilityRole="tabbar" is used on Android (#57915)

Summary:
Fixes https://github.com/react/react-native/issues/57890.

`tabbar` is part of the public `AccessibilityRole` union in both Flow and TypeScript, with nothing marking it iOS-only, and on iOS it maps to `UIAccessibilityTraitTabBar`. On Android the `AccessibilityRole` enum has no `TABBAR` entry, so `fromValue()` throws `IllegalArgumentException` from `BaseViewManager.setAccessibilityRole` during `createViewInstance` and the app crashes on mount. It is the only value in the union Android fails to resolve.

This adds `TABBAR` to the enum and maps it to `android.view.View` in `getValue`, next to `TAB` and `TABLIST`, which likewise have no dedicated Android widget. `getValue` is an exhaustive `when` with no `else`, so the second hunk is required for the enum addition to compile.

`setRole` already has an `else` branch, so no `roleDescription` is set for the new value. That looks right to me, since Android has no tab bar concept to announce, but happy to add a string resource if you'd prefer one.

## Changelog:

[ANDROID] [FIXED] - Fix crash when `accessibilityRole="tabbar"` is used on Android

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

Test Plan:
Added a unit test to `ReactAccessibilityDelegateTest` asserting that `fromValue("tabbar")` resolves to `TABBAR` and maps to `android.view.View` rather than throwing.

Repro from the issue:

```jsx
<View accessibilityRole="tabbar">
  <Text>hello</Text>
</View>
```

Before: crashes on mount on Android with `Invalid accessibility role value: tabbar`.
After: renders as a plain view, matching iOS, where roles without a UIKit trait fall back rather than raising.

I have not run the Android suite locally, relying on CI for that.

Reviewed By: christophpurrer

Differential Revision: D115730694

Pulled By: Abbondanzo

fbshipit-source-id: ab0ac7987aa0fa0a4015a08514b8d83cfaa0323c
This commit is contained in:
Aravind M Nair authored and meta-codesync[bot] committed 2026-08-12 19:43:17 -07:00
1 parent aa96fa64d1
commit a4733b1ca1
3 files changed
+12

No files matched your search

@@ -3630,6 +3630,7 @@ public final class com/facebook/react/uimanager/ReactAccessibilityDelegate$Acces
public static final field SUMMARY Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field SWITCH Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field TAB Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field TABBAR Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field TABLIST Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field TEXT Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
public static final field TIMER Lcom/facebook/react/uimanager/ReactAccessibilityDelegate$AccessibilityRole;
@@ -437,6 +437,7 @@ public open class ReactAccessibilityDelegate( // The View this delegate is attac
SPINBUTTON,
SWITCH,
TAB,
TABBAR,
TABLIST,
TIMER,
LIST,
@@ -491,6 +492,7 @@ public open class ReactAccessibilityDelegate( // The View this delegate is attac
RADIOGROUP,
SCROLLBAR,
TAB,
TABBAR,
TABLIST,
TIMER,
TOOLBAR -> "android.view.View"
@@ -347,6 +347,15 @@ class ReactAccessibilityDelegateTest {
assertThat(view.getTag(R.id.accessibility_state_expanded)).isEqualTo(true)
}
@Test
fun testAccessibilityRole_fromValue_tabbar_resolvesInsteadOfThrowing() {
val role = ReactAccessibilityDelegate.AccessibilityRole.fromValue("tabbar")
assertThat(role).isEqualTo(ReactAccessibilityDelegate.AccessibilityRole.TABBAR)
assertThat(ReactAccessibilityDelegate.AccessibilityRole.getValue(role))
.isEqualTo("android.view.View")
}
@Test
fun testPerformAccessibilityAction_collapseAction_fromAccessibilityActions() {
val accessibilityActions = JavaOnlyArray()