view LazyBear/Views/Company/Helpers/NewsList.swift @ 443:ffbb1dbab531

InsiderRosterHelper implemented
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 21 Jun 2021 20:17:46 +0200
parents 6eae10397501
children 7d1c4dc8d1d8
line wrap: on
line source

//
//  NewsList.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 21/6/21.
//

import SwiftUI

struct NewsList: View {
    var latestNews: [LatestNewsModel]
    @Environment(\.presentationMode) private var newsListPresentation
    
    var body: some View {
        NavigationView {
            ScrollView(showsIndicators: false) {
                VStack {
                    ForEach(latestNews, id: \.self) { new in
                        if !new.headline.isEmpty {
                            NewsRow(new: new)
                            Divider()
                                .padding()
                            
                        }
                    }
                }
                .padding()
            }
            .navigationTitle("Latest news")
            .toolbar {
                ToolbarItem(placement: .cancellationAction) {
                    Button(action: { newsListPresentation.wrappedValue.dismiss() }) {
                        Image(systemName: "multiply")
                    }
                }
            }
        }
    }
}

struct NewsList_Previews: PreviewProvider {
    static var previews: some View {
        NewsList(
            latestNews: [
                LatestNewsModel(
                    datetime: 1621037430000,
                    headline: "Chaos Monkeys' author calls Apple's statement on his departure defamatory",
                    image: "https://cloud.iexapis.com/v1/news/image/99abeb99-6d9e-47c8-ae7b-53404eacccec",
                    source: "Investing.com",
                    summary: "https://www.investing.com/news/stock-market-news",
                    url: "https://cloud.iexapis.com/v1/news/article/99abeb99-6d9e-47c8-ae7b-53404eacccec")
            ]
        )
    }
}