Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
🤦♂ Forgot to move the proxy out. Here's the updated code (see the GeometryProxy added):import SwiftUIstruct ContentView: View { var body: some View { GeometryStack(.top(spacing: 50)) { proxy in Color.teal Text("GeometryStack: \(proxy.size)") } }}#Preview { ContentView()}struct GeometryStack: View { private var axis: GeometryStackAxis @ViewBuilder private var content: (GeometryProxy) -> Content private var verticalAlignment: VerticalAlignment private var horizontalAlignment: HorizontalAlignment private var spacing: CGFloat? init(_ alignment: GeometryStackAlignment = .verticalCentered(spacing: nil), @ViewBuilder content: @escaping (GeometryProxy) -> Content) { switch alignment { case .leading(let spacing): self.horizontalAlignment = .leading self.verticalAlignment = .center self.spacing = spacing self.axis = .vertical case .trailing(let spacing): self.horizontalAlignment = .trailing self.verticalAlignment = .center self.spacing = spacing self.axis = .vertical case .verticalCentered(let spacing): self.horizontalAlignment = .center self.verticalAlignment = .center self.spacing = spacing self.axis = .vertical case .top(let spacing): self.horizontalAlignment = .center self.verticalAlignment = .top self.spacing = spacing self.axis = .horizontal case .bottom(let spacing): self.horizontalAlignment = .center self.verticalAlignment = .bottom self.spacing = spacing self.axis = .horizontal case .horizontalCentered(let spacing): self.horizontalAlignment = .center self.verticalAlignment = .center self.spacing = spacing self.axis = .horizontal case .depth: self.horizontalAlignment = .center self.verticalAlignment = .center self.axis = .depth } self.content = content } var body: some View { GeometryReader { proxy in Group { switch axis { case .vertical: VStack(alignment: horizontalAlignment, spacing: spacing) { content(proxy) } case .horizontal: HStack(alignment: verticalAlignment, spacing: spacing) { content(proxy) } case .depth: ZStack { content(proxy) } } } .frame(maxWidth: .infinity, maxHeight: .infinity) } } enum GeometryStackAxis { case vertical, horizontal, depth } enum GeometryStackAlignment { case leading(spacing: CGFloat?), trailing(spacing: CGFloat?), verticalCentered(spacing: CGFloat?) case top(spacing: CGFloat?), bottom(spacing: CGFloat?), horizontalCentered(spacing: CGFloat?) case depth }}
STOP using NavigationStack in SwiftUI - Navigation Coordinator is BETTER 👉 ruclips.net/video/z5IBKIGIIzA/видео.html&ab_channel=Rebeloper-RebelDeveloper
Complete wate of time.
:(
Why is making life easier for you a waste of time? I completely disagree :
🤦♂ Forgot to move the proxy out. Here's the updated code (see the GeometryProxy added):
import SwiftUI
struct ContentView: View {
var body: some View {
GeometryStack(.top(spacing: 50)) { proxy in
Color.teal
Text("GeometryStack: \(proxy.size)")
}
}
}
#Preview {
ContentView()
}
struct GeometryStack: View {
private var axis: GeometryStackAxis
@ViewBuilder private var content: (GeometryProxy) -> Content
private var verticalAlignment: VerticalAlignment
private var horizontalAlignment: HorizontalAlignment
private var spacing: CGFloat?
init(_ alignment: GeometryStackAlignment = .verticalCentered(spacing: nil),
@ViewBuilder content: @escaping (GeometryProxy) -> Content) {
switch alignment {
case .leading(let spacing):
self.horizontalAlignment = .leading
self.verticalAlignment = .center
self.spacing = spacing
self.axis = .vertical
case .trailing(let spacing):
self.horizontalAlignment = .trailing
self.verticalAlignment = .center
self.spacing = spacing
self.axis = .vertical
case .verticalCentered(let spacing):
self.horizontalAlignment = .center
self.verticalAlignment = .center
self.spacing = spacing
self.axis = .vertical
case .top(let spacing):
self.horizontalAlignment = .center
self.verticalAlignment = .top
self.spacing = spacing
self.axis = .horizontal
case .bottom(let spacing):
self.horizontalAlignment = .center
self.verticalAlignment = .bottom
self.spacing = spacing
self.axis = .horizontal
case .horizontalCentered(let spacing):
self.horizontalAlignment = .center
self.verticalAlignment = .center
self.spacing = spacing
self.axis = .horizontal
case .depth:
self.horizontalAlignment = .center
self.verticalAlignment = .center
self.axis = .depth
}
self.content = content
}
var body: some View {
GeometryReader { proxy in
Group {
switch axis {
case .vertical:
VStack(alignment: horizontalAlignment, spacing: spacing) {
content(proxy)
}
case .horizontal:
HStack(alignment: verticalAlignment, spacing: spacing) {
content(proxy)
}
case .depth:
ZStack {
content(proxy)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
enum GeometryStackAxis {
case vertical, horizontal, depth
}
enum GeometryStackAlignment {
case leading(spacing: CGFloat?), trailing(spacing: CGFloat?), verticalCentered(spacing: CGFloat?)
case top(spacing: CGFloat?), bottom(spacing: CGFloat?), horizontalCentered(spacing: CGFloat?)
case depth
}
}
STOP using NavigationStack in SwiftUI - Navigation Coordinator is BETTER 👉 ruclips.net/video/z5IBKIGIIzA/видео.html&ab_channel=Rebeloper-RebelDeveloper
Complete wate of time.
:(
Why is making life easier for you a waste of time? I completely disagree :