Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FlipcashUI/Sources/FlipcashUI/Views/Containers/Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import SwiftUI
public struct Background<Content>: 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 -
Expand All @@ -31,7 +31,7 @@ public struct Background<Content>: View where Content: View {
ZStack {
background
.edgesIgnoringSafeArea(.all)
content()
content
}
}
}
Expand Down
35 changes: 12 additions & 23 deletions FlipcashUI/Sources/FlipcashUI/Views/Containers/PartialSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,35 @@ public struct PartialSheet<T>: 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
}
}