-
Notifications
You must be signed in to change notification settings - Fork 0
/
DashboardView.swift
86 lines (79 loc) · 2.41 KB
/
DashboardView.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// DashboardView.swift
// Meine UniBi
//
// Created by Saadat Baig on 11.02.20.
// Copyright © 2020 Saadat Baig. All rights reserved.
//
import SwiftUI
// construct a Card
struct CardViewBase: View {
@Environment(\.colorScheme) var colorScheme: ColorScheme
var category: String = "Category"
var subTitle: String = "This is a subtitle"
var author: String = "Author"
var articleURL: String = ""
var body: some View {
VStack {
HStack{
VStack(alignment: .leading) {
Text(category)
.font(.headline)
.foregroundColor(colorScheme == .light ? Color.black : Color.white)
Text(subTitle)
.font(.title)
.fontWeight(.black)
.foregroundColor(colorScheme == .light ? Color.black : Color.white)
.lineLimit(3)
Text(author.uppercased())
.font(.caption)
.foregroundColor(colorScheme == .light ? Color.black : Color.white)
}
.layoutPriority(100)
Spacer()
Spacer()
}
.padding()
.onTapGesture {
let url = URL(string: self.articleURL)
UIApplication.shared.open(url!)
}
Spacer()
}
.cornerRadius(10)
.background(
RoundedRectangle(cornerRadius: 10)
.foregroundColor(colorScheme == .light ? Color.white : Color.init(red: 40/255, green: 40/255, blue: 40/255))
.shadow(radius: 5)
)
.padding([.top, .horizontal])
}
}
// View
struct DashboardView: View {
// data
@ObservedObject var rssList = unibiRSSList()
var body: some View {
if (self.rssList.contentList.count != 0) {
return AnyView(ScrollView {
ForEach(rssList.contentList, id: \.id) { i in
CardViewBase(category: i.category, subTitle: i.title, author: i.publishedDate, articleURL: i.link)
}
})
} else {
return AnyView(Text("Loading..."))
}
}
}
// debugView
struct debugView : View {
var body: some View {
CardViewBase()
}
}
// Preview
struct DashboardView_Previews: PreviewProvider {
static var previews: some View {
debugView()
}
}