Commit a4733b1
Fix crash when accessibilityRole="tabbar" is used on Android (#57915)
Summary:
Fixes #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: #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: ab0ac7987aa0fa0a4015a08514b8d83cfaa0323c1 parent aa96fa6 commit a4733b1
3 files changed
Lines changed: 12 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid
- api
- src
- main/java/com/facebook/react/uimanager
- test/java/com/facebook/react/uimanager
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3630 | 3630 | | |
3631 | 3631 | | |
3632 | 3632 | | |
| 3633 | + | |
3633 | 3634 | | |
3634 | 3635 | | |
3635 | 3636 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| 440 | + | |
440 | 441 | | |
441 | 442 | | |
442 | 443 | | |
| |||
491 | 492 | | |
492 | 493 | | |
493 | 494 | | |
| 495 | + | |
494 | 496 | | |
495 | 497 | | |
496 | 498 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
350 | 359 | | |
351 | 360 | | |
352 | 361 | | |
| |||
0 commit comments