From 64dc8759f8c829e3df59d31bf0838e928f024b3c Mon Sep 17 00:00:00 2001 From: Raul Riera Date: Fri, 26 Dec 2025 14:04:06 -0500 Subject: [PATCH] fix(sheet): the sheet no longer animates from the left --- .../Views/Containers/Background.swift | 12 +++---- .../Views/Containers/PartialSheet.swift | 35 +++++++------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/FlipcashUI/Sources/FlipcashUI/Views/Containers/Background.swift b/FlipcashUI/Sources/FlipcashUI/Views/Containers/Background.swift index 45ba6313..655d4078 100644 --- a/FlipcashUI/Sources/FlipcashUI/Views/Containers/Background.swift +++ b/FlipcashUI/Sources/FlipcashUI/Views/Containers/Background.swift @@ -11,18 +11,18 @@ import SwiftUI public struct Background: View where Content: View { public var background: AnyView - public var content: () -> Content + public var content: Content // MARK: - Init - - public init(color: Color, @ViewBuilder content: @escaping () -> Content) { + public init(color: Color, @ViewBuilder content: () -> Content) { self.background = AnyView(color) - self.content = content + self.content = content() } - public init(gradient: LinearGradient, @ViewBuilder content: @escaping () -> Content) { + public init(gradient: LinearGradient, @ViewBuilder content: () -> Content) { self.background = AnyView(gradient) - self.content = content + self.content = content() } // MARK: - Body - @@ -31,7 +31,7 @@ public struct Background: View where Content: View { ZStack { background .edgesIgnoringSafeArea(.all) - content() + content } } } diff --git a/FlipcashUI/Sources/FlipcashUI/Views/Containers/PartialSheet.swift b/FlipcashUI/Sources/FlipcashUI/Views/Containers/PartialSheet.swift index 65d43f03..92e75b33 100644 --- a/FlipcashUI/Sources/FlipcashUI/Views/Containers/PartialSheet.swift +++ b/FlipcashUI/Sources/FlipcashUI/Views/Containers/PartialSheet.swift @@ -13,46 +13,35 @@ public struct PartialSheet: View where T: View { public let background: Color public let canDismiss: Bool public let canAccessBackground: Bool - public let content: () -> T + public let content: T - @State private var displayHeight: CGFloat = 0 { - didSet { - print("Partial sheet \(displayHeight)") - } - } + @State private var displayHeight: CGFloat = UIScreen.main.bounds.height - public init(background: Color = .backgroundMain, canDismiss: Bool = true, canAccessBackground: Bool = false, @ViewBuilder content: @escaping () -> T) { + public init(background: Color = .backgroundMain, canDismiss: Bool = true, canAccessBackground: Bool = false, @ViewBuilder content: () -> T) { self.background = background self.canDismiss = canDismiss self.canAccessBackground = canAccessBackground - self.content = content + self.content = content() } public var body: some View { Background(color: background) { - content() + content + .frame(maxWidth: .infinity) .overlay { GeometryReader { g in Color.clear - .preference(key: LayoutHeightPreferenceKey.self, value: g.size.height) + .onAppear { + displayHeight = g.size.height + } + .onChange(of: g.size.height) { _, newHeight in + displayHeight = newHeight + } } } } - .onPreferenceChange(LayoutHeightPreferenceKey.self) { value in - displayHeight = value ?? 0 - } .presentationDetents([.height(displayHeight)]) .presentationBackgroundInteraction(canAccessBackground ? .enabled : .disabled) .interactiveDismissDisabled(!canDismiss) } } - -private struct LayoutHeightPreferenceKey: PreferenceKey { - typealias Value = CGFloat? - - static let defaultValue: Value = nil - - static func reduce(value: inout Value, nextValue: () -> Value) { - value = nextValue() ?? value - } -}