Mercurial > public > lazybear
changeset 261:f9d6a324e3d2
Add in-app Safari view
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 13 Mar 2021 14:23:05 +0100 |
parents | deb436f21e88 |
children | cd902f3f7f33 |
files | LazyBear/Tests/TestSafari.swift LazyBear/UI/DetailNew.swift LazyBear/UI/NewsRow.swift LazyBear/UI/SafariView.swift |
diffstat | 4 files changed, 26 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear/Tests/TestSafari.swift Sat Mar 13 14:18:59 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -// -// TestSafari.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 13/3/21. -// - -import SwiftUI - -struct TestSafari: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - } -} - -struct TestSafari_Previews: PreviewProvider { - static var previews: some View { - TestSafari() - } -}
--- a/LazyBear/UI/DetailNew.swift Sat Mar 13 14:18:59 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -// -// DetailNew.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 3/3/21. -// - -import SwiftUI -import SDWebImageSwiftUI - -struct DetailNew: View { - var new: NewsModel - - var body: some View { - NavigationView { - ScrollView(showsIndicators: false) { - VStack(alignment: .leading) { - Text(new.headline ?? "") - .font(.title2) - .fontWeight(.semibold) - .padding(.horizontal) - .padding(.top) - - VStack(alignment: .leading) { - WebImage(url: URL(string: new.image ?? "")) - .resizable() - .indicator(.activity) - .scaledToFit() - - Text(new.summary ?? "") - .padding(.horizontal) - - Link("Read the full story", destination: URL(string: new.url ?? "")!) - .padding(.horizontal) - .padding(.top) - } - } - } - .navigationTitle(new.source ?? "-") - .navigationBarTitleDisplayMode(.inline) - } - } -} - -struct DetailNew_Previews: PreviewProvider { - static var previews: some View { - DetailNew(new: NewsModel(datetime: 1613838000000, headline: "As Facebook, Microsoft, Apple, Uber, Amazon, and others play larger roles in OpenStreetMap, hobbyists fear private sector will overshadow their work (Corey Dickinson/Bloomberg)", source: "Techmeme", url: "https://cloud.iexapis.com/v1/news/article/d760b0bc-42f0-4ed0-a721-a7691eeaa132", summary: "Corey Dickinson / Bloomberg : As Facebook, Microsoft, Apple, Uber, Amazon, and others play larger roles in OpenStreetMap, hobbyists fear private sector will overshadow their work — What do Lyft, Facebook, the International Red Cross, the U.N., the government of Nepal and Pokémon Go have in common?", image: "https://cloud.iexapis.com/v1/news/image/d760b0bc-42f0-4ed0-a721-a7691eeaa132")) - } -}
--- a/LazyBear/UI/NewsRow.swift Sat Mar 13 14:18:59 2021 +0100 +++ b/LazyBear/UI/NewsRow.swift Sat Mar 13 14:23:05 2021 +0100 @@ -10,11 +10,11 @@ struct NewsRow: View { var new: NewsModel - @State var showingDetail = false + @State var showingSafari = false @Environment(\.colorScheme) var colorScheme // Detect dark mode var body: some View { - Button(action: { self.showingDetail = true }) { + Button(action: { self.showingSafari = true }) { VStack(alignment: .leading) { // If iPad show Image if UIDevice.current.userInterfaceIdiom == .pad { @@ -56,8 +56,8 @@ } } .foregroundColor(colorScheme == .dark ? .white: .black) - .sheet(isPresented: $showingDetail) { - DetailNew(new: new) + .sheet(isPresented: $showingSafari) { + SafariView(url:URL(string: new.url ?? "")!) } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/UI/SafariView.swift Sat Mar 13 14:23:05 2021 +0100 @@ -0,0 +1,22 @@ +// +// SafariView.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 13/3/21. +// + +import SwiftUI +import SafariServices + +struct SafariView: UIViewControllerRepresentable { + let url: URL + + func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController { + return SFSafariViewController(url: url) + } + + func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) { + + } + +}