diff --git a/.changeset/bright-taxes-cheat.md b/.changeset/bright-taxes-cheat.md new file mode 100644 index 00000000..c5d55cba --- /dev/null +++ b/.changeset/bright-taxes-cheat.md @@ -0,0 +1,5 @@ +--- +'react-native-bottom-tabs': patch +--- + +Fix phantom tab switch on iOS when scene re-appears diff --git a/packages/react-native-bottom-tabs/ios/TabAppearModifier.swift b/packages/react-native-bottom-tabs/ios/TabAppearModifier.swift index 58d1855a..4d8aa04d 100644 --- a/packages/react-native-bottom-tabs/ios/TabAppearModifier.swift +++ b/packages/react-native-bottom-tabs/ios/TabAppearModifier.swift @@ -18,7 +18,12 @@ struct TabAppearModifier: ViewModifier { #endif #if os(iOS) - if context.index >= 4, context.props.selectedPage != context.tabData.key { + // Sync selection for tabs nested under the system "More" tab, which + // only exists when there are more than 5 visible tabs. Without the + // count guard the 5th tab (index 4) of a non-overflowing bar would + // force-select itself whenever its scene re-appears (e.g. when the tab + // bar is re-shown after `.hideTabBar`), hijacking the selection. + if context.props.filteredItems.count > 5, context.index >= 4, context.props.selectedPage != context.tabData.key { context.onSelect(context.tabData.key) } #endif