fix: use tab role on Android for accessibility

This commit is contained in:
Satyajit Sahoo
2021-03-22 19:21:47 +01:00
parent cbaabc1288
commit de805a3ebf
2 changed files with 8 additions and 3 deletions

View File

@@ -285,7 +285,11 @@ export default function BottomTabBar({
]}
pointerEvents={isTabBarHidden ? 'none' : 'auto'}
>
<View style={styles.content} onLayout={handleLayout}>
<View
accessibilityRole="tablist"
style={styles.content}
onLayout={handleLayout}
>
{routes.map((route, index) => {
const focused = index === state.index;
const { options } = descriptors[route.key];
@@ -322,7 +326,7 @@ export default function BottomTabBar({
const accessibilityLabel =
options.tabBarAccessibilityLabel !== undefined
? options.tabBarAccessibilityLabel
: typeof label === 'string'
: typeof label === 'string' && Platform.OS === 'ios'
? `${label}, tab, ${index + 1} of ${routes.length}`
: undefined;

View File

@@ -263,7 +263,8 @@ export default function BottomTabBarItem({
onLongPress,
testID,
accessibilityLabel,
accessibilityRole: 'button',
// FIXME: accessibilityRole: 'tab' doesn't seem to work as expected on iOS
accessibilityRole: Platform.select({ ios: 'button', default: 'tab' }),
accessibilityState: { selected: focused },
// @ts-expect-error: keep for compatibility with older React Native versions
accessibilityStates: focused ? ['selected'] : [],