-
-
Notifications
You must be signed in to change notification settings - Fork 505
Expand file tree
/
Copy pathAlternateLayoutView.swift
More file actions
49 lines (42 loc) · 1.32 KB
/
AlternateLayoutView.swift
File metadata and controls
49 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2026 Jellyfin & Jellyfin Contributors
//
import SwiftUI
/// A view that takes a view to affect layout while overlaying the content.
struct AlternateLayoutView<Content: View, Layout: View>: View {
@State
private var layoutFrame: CGRect = .zero
private let alignment: Alignment
private let content: (CGSize) -> Content
private let layout: Layout
init(
alignment: Alignment = .center,
@ViewBuilder layout: @escaping () -> Layout,
@ViewBuilder content: @escaping () -> Content
) {
self.alignment = alignment
self.content = { _ in content() }
self.layout = layout()
}
init(
alignment: Alignment = .center,
@ViewBuilder layout: @escaping () -> Layout,
@ViewBuilder content: @escaping (CGSize) -> Content
) {
self.alignment = alignment
self.content = content
self.layout = layout()
}
var body: some View {
layout
.hidden()
.trackingFrame($layoutFrame)
.overlay(alignment: alignment) {
content(layoutFrame.size)
}
}
}