Tab Navigator and Stack Navigator: Does deep‑link navigation announce screen titles for accessibility?
0 reputation · 13 Dec 2021, 08:05 UTC
0 reputation · 13 Dec 2021, 08:05 UTC
Goal: Verify that a screen’s title is announced by TalkBack or VoiceOver when the user arrives at that screen through a deep link or a programmatic reset that targets a navigator nested inside another navigator (for example, a stack inside a tab). React Navigation already moves accessibility focus to the new screen and announces the title for top‑level stack navigators, but the same automatic announcement is not observed for nested navigators, leaving the screen silent unless developers manually call AccessibilityInfo.announceForAccessibility.
The inconsistency appears in version 6.x, where the focus‑handling refactor may have changed how title announcements propagate through nested state changes, and it is unclear whether this is an intentional omission, a bug, or a missing configuration option.
Should React Navigation automatically announce the screen title for deep‑link or reset navigation into a nested navigator? Is there a supported prop or configuration to enable this behavior without manual announcements? Does the current accessibility focus handling guarantee title announcements for all navigator depths, or is additional work required from the library?
29775 reputation · 13 Dec 2021, 12:12 UTC
No. React Navigation 6.x does not automatically announce screen titles when a deep link or programmatic reset targets a navigator nested inside another navigator (for example, a StackNavigator inside a TabNavigator). The library’s built-in accessibility focus handling only announces titles for top-level stack transitions. Nested navigator state changes do not bubble an announcement event, and there is no supported prop or configuration (such as announceTitle or accessibilityAnnounce) to enable this behavior in v6.x.
React Navigation’s NavigationContainer and the useNavigation focus handlers propagate accessibility focus to the immediate active screen of the root navigator. When a deep link like navigation.navigate('Root', { screen: 'TabTwo', params: { screen: 'NestedDetail' } }) resolves, the nested stack updates its internal state, but the root navigator’s focus manager does not treat this as a screen change that warrants a title announcement. The refactor in v6.x that centralized focus handling inadvertently left nested transitions without an announcement path.
Until a future RFC adds a standardized accessibilityAnnounce hook, the maintainers recommend manually announcing the title. Attach a state listener to the nested navigator:
import { AccessibilityInfo } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
function NestedStack() {
const navigation = useNavigation();
React.useEffect(() => {
const unsub = navigation.addListener('state', (state) => {
const route = state.routes[state.index];
if (route?.name) {
AccessibilityInfo.announceForAccessibility(route.name);
}
});
return unsub;
}, [navigation]);
return (
<Stack.Navigator
screenOptions={({ route }) => ({ headerTitle: route.name })}
>
{/* screens */}
</Stack.Navigator>
);
}Guard the announcement with navigation.isFocused() or a debounce to avoid overload when multiple state events fire rapidly.
TabNavigator with two tabs; the second tab contains a StackNavigator with two screens.navigation.navigate('Root', { screen: 'TabTwo', params: { screen: 'NestedDetail' } }).Which exact React Navigation version (e.g., 6.1.9, 6.0.0) and React Native version are you testing on? The behavior is consistent across the 6.x line, but a patch release could introduce a regression or partial fix that changes the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.