-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlbumGrid.swift
62 lines (50 loc) · 1.33 KB
/
AlbumGrid.swift
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
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
The grid view of loaded albums.
*/
import SwiftUI
struct AlbumGrid: View {
// MARK: Properties
@State private var isSheetPresented = false
@Environment(MediaLibrary.self) private var library
private let columns = [
GridItem(.adaptive(minimum: 300))
]
// MARK: Lifecycle
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(library.albums) { album in
NavigationLink(value: album) {
AlbumItem(album: album)
}
.buttonStyle(.plain)
}
}
#if os(macOS)
.padding()
#endif
}
.navigationTitle("Albums")
.navigationDestination(for: Album.self) { album in
AlbumDetailView(album: album)
}
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Add", systemImage: "plus", action: addAlbum)
}
}
.sheet(isPresented: $isSheetPresented) {
AlbumNameView()
}
}
// MARK: Methods
private func addAlbum() {
isSheetPresented = true
}
}
#Preview {
AlbumGrid()
.environment(MediaLibrary())
}