From c89c80e8d17b5ad471f4b0eacfc28ce071b1867e Mon Sep 17 00:00:00 2001 From: Daniel Arantes Loverde Date: Wed, 3 Jun 2026 15:20:44 -0300 Subject: [PATCH] fix(store): replace pinnedViews with ZStack overlay to prevent EXC_BAD_ACCESS crash pinnedViews + rapid state changes from stretchAmount every frame during overscroll triggers SwiftUI memory corruption. ZStack overlay approach is crash-free: - LazyVStack with no pinnedViews - Inline tabs fade out when pinned threshold reached - Overlay tabs (with safeAreaTop padding) fade in at top of ZStack --- .../Views/Main/StoreDetailView.swift | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/pedi-foods/Sources/PediFoods/Views/Main/StoreDetailView.swift b/pedi-foods/Sources/PediFoods/Views/Main/StoreDetailView.swift index 4d5bba6..5e6761a 100644 --- a/pedi-foods/Sources/PediFoods/Views/Main/StoreDetailView.swift +++ b/pedi-foods/Sources/PediFoods/Views/Main/StoreDetailView.swift @@ -46,25 +46,39 @@ struct StoreDetailView: View { let coverVisibleUntilY: CGFloat = 253 let storeLogoSize: CGFloat = 84 + var safeAreaTop: CGFloat { + #if canImport(UIKit) + return UIDevice.appSafeAreaTop + #else + return 0 + #endif + } + var body: some View { ScrollViewReader { proxy in - ScrollView(showsIndicators: false) { - ScrollOffsetReader(offsetY: $scrollOffset) - LazyVStack(spacing: 0, pinnedViews: [.sectionHeaders]) { - topSection - Section { + ZStack(alignment: .top) { + ScrollView(showsIndicators: false) { + ScrollOffsetReader(offsetY: $scrollOffset) + LazyVStack(spacing: 0) { + topSection + categoryTabs(proxy: proxy, isPinned: false) + .opacity(isCategoryTabsPinned ? 0 : 1) sectionedProducts - } header: { - categoryTabs(proxy: proxy, isPinned: isCategoryTabsPinned) } } - } - .coordinateSpace(name: StoreDetailScrollCoordinateSpace.name) - .refreshable { - await loadStoreData(forceRefresh: true) + .coordinateSpace(name: StoreDetailScrollCoordinateSpace.name) + .refreshable { + await loadStoreData(forceRefresh: true) + } + .ignoresSafeArea(edges: .top) + .background(AppColors.backgroundLight) + + categoryTabs(proxy: proxy, isPinned: true) + .opacity(isCategoryTabsPinned ? 1 : 0) + .allowsHitTesting(isCategoryTabsPinned) + .zIndex(10) } .ignoresSafeArea(edges: .top) - .background(AppColors.backgroundLight) .saturation(isStoreOpen ? 1 : 0) } .navigationBarBackButtonHidden(true)