forked from shadowfacts/Tusker
60 lines
1.5 KiB
Swift
60 lines
1.5 KiB
Swift
//
|
|
// MaybeLazyStack.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 10/10/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MaybeLazyVStack<Content: View>: View {
|
|
private let alignment: HorizontalAlignment
|
|
private let spacing: CGFloat?
|
|
private let content: Content
|
|
|
|
init(alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content) {
|
|
self.alignment = alignment
|
|
self.spacing = spacing
|
|
self.content = content()
|
|
}
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
if #available(iOS 14.0, *) {
|
|
LazyVStack(alignment: alignment, spacing: spacing) {
|
|
content
|
|
}
|
|
} else {
|
|
VStack(alignment: alignment, spacing: spacing) {
|
|
content
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MaybeLazyHStack<Content: View>: View {
|
|
private let alignment: VerticalAlignment
|
|
private let spacing: CGFloat?
|
|
private let content: Content
|
|
|
|
init(alignment: VerticalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content) {
|
|
self.alignment = alignment
|
|
self.spacing = spacing
|
|
self.content = content()
|
|
}
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
if #available(iOS 14.0, *) {
|
|
LazyHStack(alignment: alignment, spacing: spacing) {
|
|
content
|
|
}
|
|
} else {
|
|
HStack(alignment: alignment, spacing: spacing) {
|
|
content
|
|
}
|
|
}
|
|
}
|
|
}
|