Wix react-native-navigation 4.2.0:关闭模态框同时切换标签页可行吗?
Hey there! Let's break down this problem for you.
In v4.2.0 of React Native Navigation, the dismissModal method doesn't support passing bottomTabs configuration directly in its options parameter. The options object you tried to use is only intended for controlling the modal's dismissal animations and behavior—not for modifying the bottom tabs state after the modal closes. That's why your initial code didn't work.
The Fix: Switch Tabs After Dismissing the Modal
To achieve what you want, you need to trigger the tab switch once the modal has finished dismissing. Here's how to do it properly:
Option 1: Use findComponentIdForName to Target Bottom Tabs
If you know the registered name of your bottom tabs screen, you can retrieve its component ID directly:
Navigation.dismissModal(componentId, () => { // Replace 'YourBottomTabsScreen' with your actual bottom tabs screen name const bottomTabsComponentId = Navigation.findComponentIdForName('YourBottomTabsScreen'); // Switch to the desired tab (index 1 in your example) Navigation.mergeOptions(bottomTabsComponentId, { bottomTabs: { currentTabIndex: 1 } }); });
Option 2: Use getParent for More Reliability
If your modal was presented from a screen inside the bottom tabs, you can fetch the bottom tabs' component ID via the modal's parent. Note that in v4.x, getParent returns a promise, so we'll use async/await:
Navigation.dismissModal(componentId, async () => { // Get the parent bottom tabs component ID from the modal's originating screen const bottomTabsComponentId = await Navigation.getParent(componentId); Navigation.mergeOptions(bottomTabsComponentId, { bottomTabs: { currentTabIndex: 1 } }); });
Either approach will ensure that the modal closes first, then the bottom tab switches to your target index.
内容的提问来源于stack exchange,提问作者Kevin Amiranoff

