-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostRow.swift
67 lines (59 loc) · 1.61 KB
/
PostRow.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
63
64
65
66
//
// RssRow.swift
// iosApp
//
// Created by Ekaterina.Petrova on 25.10.2020.
// Copyright © 2020 orgName. All rights reserved.
//
import SwiftUI
import RssReader
import URLImage
struct PostRow: View {
let post: Post
var body: some View {
if let postURL = post.linkURL {
Link(destination: postURL) {
content
}
.foregroundColor(.black)
} else {
content
}
}
var content: some View {
VStack(alignment: .leading, spacing: 10.0) {
Text(post.title).bold().font(.title3)
if let imageUrl = post.imageUrl, let url = URL(string: imageUrl) {
URLImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
}
.frame(minWidth: 0, maxWidth: .infinity)
.clipped()
}
Text(post.desc ?? "").font(.body)
HStack{
Spacer()
Text(post.dateString).font(.footnote).foregroundColor(.gray)
}
}
}
}
extension Post {
static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "E, MMM d HH:mm"
return formatter
}()
var dateString: String {
return Post.dateFormatter.string(from: Date(timeIntervalSince1970: TimeInterval(date)))
}
var linkURL: URL? {
if let link = link {
return URL(string: link)
} else {
return nil
}
}
}