From a4733b1ca13c5b4bcce280c079343f27636a033a Mon Sep 17 00:00:00 2001 From: Aravind M Nair Date: Wed, 12 Aug 2026 19:43:17 -0700 Subject: [PATCH] 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 hello ``` 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 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 1 + .../react/uimanager/ReactAccessibilityDelegate.kt | 2 ++ .../react/uimanager/ReactAccessibilityDelegateTest.kt | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index f05157f9262..4d0e582d353 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -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; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.kt index c56a5201e91..e6c12f6368e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.kt @@ -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" diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactAccessibilityDelegateTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactAccessibilityDelegateTest.kt index 8b7c303bdf7..30d16023d7e 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactAccessibilityDelegateTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactAccessibilityDelegateTest.kt @@ -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()