Skip to content

Commit 942e441

Browse files
davidecallegaroclaudethiagobrez
authored
fix(ios): gate index>=4 appear-select on >5-tab overflow (#526)
* fix(ios): gate index>=4 appear-select on >5-tab overflow TabAppearModifier force-selected any tab with index >= 4 on appear to sync selection for tabs under the system More tab. That overflow only exists with more than 5 visible tabs, so on a 5-tab bar the 5th tab (index 4) hijacked the selection whenever its scene re-appeared (e.g. when the tab bar is re-shown after .hideTabBar), causing a phantom tab switch that JS can't correct. Gate the force-select on filteredItems.count > 5. Fixes #525. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: add changeset --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Thiago Brezinski <thiagobrez@gmail.com>
1 parent 412e9ca commit 942e441

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

.changeset/bright-taxes-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-bottom-tabs': patch
3+
---
4+
5+
Fix phantom tab switch on iOS when scene re-appears

packages/react-native-bottom-tabs/ios/TabAppearModifier.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ struct TabAppearModifier: ViewModifier {
1818
#endif
1919

2020
#if os(iOS)
21-
if context.index >= 4, context.props.selectedPage != context.tabData.key {
21+
// Sync selection for tabs nested under the system "More" tab, which
22+
// only exists when there are more than 5 visible tabs. Without the
23+
// count guard the 5th tab (index 4) of a non-overflowing bar would
24+
// force-select itself whenever its scene re-appears (e.g. when the tab
25+
// bar is re-shown after `.hideTabBar`), hijacking the selection.
26+
if context.props.filteredItems.count > 5, context.index >= 4, context.props.selectedPage != context.tabData.key {
2227
context.onSelect(context.tabData.key)
2328
}
2429
#endif

0 commit comments

Comments
 (0)