comparison LazyBear/Views/Company/Helpers/NewsRow.swift @ 442:6eae10397501

Implementing NewsHelper in CompanyView
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 21 Jun 2021 13:28:45 +0200
parents
children ffbb1dbab531
comparison
equal deleted inserted replaced
441:417148200aaf 442:6eae10397501
1 //
2 // NewsRow.swift
3 // LazyBear
4 //
5 // Created by Dennis Concepción Martín on 21/6/21.
6 //
7
8 import SwiftUI
9 import SDWebImageSwiftUI
10
11 struct NewsRow: View {
12 var new: LatestNewsModel
13 @State private var showWebArticle = false
14
15 var body: some View {
16 HStack {
17 RoundedRectangle(cornerRadius: 10)
18 .frame(width: 65, height: 65, alignment: .center)
19 .overlay(
20 WebImage(url: URL(string: new.image))
21 .resizable()
22 .placeholder {
23 Rectangle()
24 .foregroundColor(.gray)
25 }
26 .indicator(.activity)
27 .scaledToFill()
28 )
29 .clipShape(RoundedRectangle(cornerRadius: 10))
30
31 VStack(alignment: .leading) {
32 Text(new.headline)
33 .font(.callout)
34 .fontWeight(.semibold)
35 .fixedSize(horizontal: false, vertical: true) /// I need to add this to make lineLimit works correctly
36 .lineLimit(3)
37 }
38 .padding(.horizontal, 5)
39
40 Button(action: { showWebArticle = true }) {
41 Capsule()
42 .foregroundColor(Color(.secondarySystemBackground))
43 .frame(width: 80, height: 35, alignment: .center)
44 .overlay(
45 Text("READ")
46 .font(.headline)
47 )
48 }
49 }
50 .sheet(isPresented: $showWebArticle) {
51 SFSafariViewWrapper(url: URL(string: new.url)!)
52 .edgesIgnoringSafeArea(.bottom)
53 }
54 }
55 }
56
57 struct NewsRow_Previews: PreviewProvider {
58 static var previews: some View {
59 NewsRow(
60 new: LatestNewsModel(
61 datetime: 1621037430000,
62 headline: "Chaos Monkeys' author calls Apple's statement on his departure defamatory",
63 image: "https://cloud.iexapis.com/v1/news/image/99abeb99-6d9e-47c8-ae7b-53404eacccec",
64 source: "Investing.com",
65 summary: "https://www.investing.com/news/stock-market-news",
66 url: "https://bloomberg.com")
67 )
68 }
69 }