# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1615641785 -3600 # Node ID f9d6a324e3d2e274ebe7148ed7618eaf17a02215 # Parent deb436f21e88828bc594db4bc912f6e245a8fa24 Add in-app Safari view diff -r deb436f21e88 -r f9d6a324e3d2 LazyBear/Tests/TestSafari.swift --- 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() - } -} diff -r deb436f21e88 -r f9d6a324e3d2 LazyBear/UI/DetailNew.swift --- 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")) - } -} diff -r deb436f21e88 -r f9d6a324e3d2 LazyBear/UI/NewsRow.swift --- 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 ?? "")!) } } diff -r deb436f21e88 -r f9d6a324e3d2 LazyBear/UI/SafariView.swift --- /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) -> SFSafariViewController { + return SFSafariViewController(url: url) + } + + func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext) { + + } + +}