forked from MacMagazine/app-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedDetailView.swift
More file actions
90 lines (71 loc) · 1.98 KB
/
FeedDetailView.swift
File metadata and controls
90 lines (71 loc) · 1.98 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import FeedLibrary
import SwiftUI
struct FeedDetailView: View {
@Environment(\.modelContext) private var modelContext
// MARK: - Properties
let post: FeedDB
@StateObject private var viewModel: FeedMainViewModel
// MARK: - Init
init(viewModel: FeedMainViewModel, post: FeedDB) {
self.post = post
_viewModel = StateObject(wrappedValue: viewModel)
}
// MARK: - Body
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
header
bodyText
footer
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.contentShape(Rectangle())
}
.navigationTitle("Notícia")
.navigationBarTitleDisplayMode(.inline)
}
// MARK: - Header
private var header: some View {
VStack(alignment: .leading, spacing: 6) {
Text(post.title)
.font(.headline)
.bold()
.lineLimit(3)
Text(post.dateText)
.font(.footnote)
.foregroundStyle(.secondary)
}
}
// MARK: - Body
@ViewBuilder
private var bodyText: some View {
if let content = post.displayBody {
Divider()
.padding(.vertical, 4)
Text(content)
.font(.body)
.multilineTextAlignment(.leading)
}
}
// MARK: - Footer
private var footer: some View {
VStack(spacing: 8) {
Divider()
.padding(.top, 4)
Button {
viewModel.toggleFavorite(post: post, modelContext: modelContext)
} label: {
Image(systemName: post.favorite ? "star.fill" : "star")
}
.buttonStyle(.glass)
}
}
}
// MARK: - Preview
#if DEBUG
#Preview {
FeedDetailView(viewModel: .preview(status: .done),
post: .previewItem)
}
#endif