From 52e6c51d9da46a51c469e64ba71339ad789bf6ff Mon Sep 17 00:00:00 2001 From: Jonathan Cottrell Date: Tue, 26 Jul 2022 11:29:11 -0700 Subject: [PATCH] Use EmptyView when geometry reader is still sized at 0 --- Sources/BottomSheet/BottomSheet.swift | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Sources/BottomSheet/BottomSheet.swift b/Sources/BottomSheet/BottomSheet.swift index f287ae7..c9baf28 100644 --- a/Sources/BottomSheet/BottomSheet.swift +++ b/Sources/BottomSheet/BottomSheet.swift @@ -52,21 +52,25 @@ public struct BottomSheet: View { public var body: some View { GeometryReader { geometry in - ZStack { - self.fullScreenLightGrayOverlay() - VStack(spacing: 0) { - self.topBar(geometry: geometry) - VStack(spacing: -8) { - Spacer() - self.content.padding(.bottom, geometry.safeAreaInsets.bottom) - Spacer() + if geometry.size != .zero { + ZStack { + self.fullScreenLightGrayOverlay() + VStack(spacing: 0) { + self.topBar(geometry: geometry) + VStack(spacing: -8) { + Spacer() + self.content.padding(.bottom, geometry.safeAreaInsets.bottom) + Spacer() + } } + .frame(height: sheetHeight(in: geometry) - min(self.draggedOffset*2, 0)) + .background(self.contentBackgroundColor) + .cornerRadius(self.topBarCornerRadius, corners: [.topLeft, .topRight]) + .animation(.interactiveSpring()) + .offset(y: self.isPresented ? (geometry.size.height/2 - sheetHeight(in: geometry)/2 + geometry.safeAreaInsets.bottom + self.draggedOffset) : (geometry.size.height/2 + sheetHeight(in: geometry)/2 + geometry.safeAreaInsets.bottom)) } - .frame(height: sheetHeight(in: geometry) - min(self.draggedOffset*2, 0)) - .background(self.contentBackgroundColor) - .cornerRadius(self.topBarCornerRadius, corners: [.topLeft, .topRight]) - .animation(.interactiveSpring()) - .offset(y: self.isPresented ? (geometry.size.height/2 - sheetHeight(in: geometry)/2 + geometry.safeAreaInsets.bottom + self.draggedOffset) : (geometry.size.height/2 + sheetHeight(in: geometry)/2 + geometry.safeAreaInsets.bottom)) + } else { + EmptyView() } } }