I have a SwiftUI app that I want to maintain iOS 13 support for, but on iOS 14 I want to use the new LazyVStack
and LazyHStack
. I was thinking ty
Here is possible wrapper that can be used as regular stack container
struct CompatibleVStack : View where Content : View {
let alignment: HorizontalAlignment
let spacing: CGFloat?
let content: () -> Content
init(alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil,
@ViewBuilder content: @escaping () -> Content) {
self.alignment = alignment
self.spacing = spacing
self.content = content
}
var body: some View {
Group {
if #available(iOS 14, *) { // << add more platforms if needed
LazyVStack(alignment: alignment, spacing: spacing, pinnedViews: [], content:content)
} else {
VStack(alignment: alignment, spacing: spacing, content:content)
}
}
}
}