Skip to content

Commit a80274f

Browse files
jholwillclaude
andcommitted
Fix tabs not updating stateful child components on tab switch
When switching tabs, SwiftUI reuses LoadedTabComponentView at the same structural position, preserving @State from the previous tab's children (e.g. Carousel page data, scroll index). Adding .id(selectedTabId) forces a full view recreation on each tab switch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bfbca16 commit a80274f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

RevenueCatUI/Templates/V2/Components/Tabs/TabsComponentView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ struct LoadedTabsComponentView: View {
222222
},
223223
onDismiss: self.onDismiss
224224
)
225+
// Force SwiftUI to recreate tab content when the selected tab changes.
226+
.id(self.tabControlContext.selectedTabId)
225227
.environmentObject(self.tabControlContext)
226228
.environmentObject(tierPackageContext)
227229
.onAppear {

0 commit comments

Comments
 (0)