diff --git a/Hydra iOS/Models/UgentNewsItem.swift b/Hydra iOS/Models/UgentNewsItem.swift index c2e5b09..195c1c2 100644 --- a/Hydra iOS/Models/UgentNewsItem.swift +++ b/Hydra iOS/Models/UgentNewsItem.swift @@ -9,10 +9,13 @@ import Foundation struct UgentNewsItem: Decodable, Identifiable { let id: String - let content: String let link: String let published: Date let summary: String let title: String var orgPath: String? = "logo-ugent-en" + + private enum CodingKeys: String, CodingKey { + case id, link, published, summary, title + } } diff --git a/Hydra iOS/Views/Overview.swift b/Hydra iOS/Views/Overview.swift index d284ba3..6cb2582 100644 --- a/Hydra iOS/Views/Overview.swift +++ b/Hydra iOS/Views/Overview.swift @@ -6,7 +6,7 @@ // import SwiftUI -import SwiftUIPullToRefresh +import RefreshableScrollView struct Overview: View { @Environment(\.managedObjectContext) private var viewContext; @@ -17,27 +17,24 @@ struct Overview: View { } var body: some View { - GeometryReader { geometry in - RefreshableScrollView(showsIndicators: false, loadingViewBackgroundColor: Color.white, onRefresh: {done in - DispatchQueue.main.asyncAfter(deadline: .now()) { - newsItemStorage.refresh() - done() - } - }) { - NavigationView { - VStack { - if (newsItemStorage.loading) { - ProgressView("Loading") - } else { - List (newsItemStorage.newsItems) { - item in NewsEntry(title: item.title, link: item.link) - } + NavigationView { + VStack { + if (newsItemStorage.loading) { + ProgressView("Loading") + } else { + ScrollView { + ForEach(newsItemStorage.newsItems) { + item in NewsEntry(orgPath: item.orgPath, title: item.title, link: item.link) + } + }.onRefresh(spinningColor: Color(UIColor.systemGray), text: "Pull to refresh", textColor: Color(UIColor.systemGray), backgroundColor: Color(UIColor.systemBackground)) { refreshControl in + DispatchQueue.main.async { + newsItemStorage.refresh() + refreshControl.endRefreshing() } } - .navigationTitle(Text("Hydra")) } - .frame(width: geometry.size.width, height: geometry.size.height, alignment: .center) } + .navigationTitle(Text("Hydra")) } } } diff --git a/Hydra.xcodeproj/project.pbxproj b/Hydra.xcodeproj/project.pbxproj index 366ad72..6a8e2f8 100644 --- a/Hydra.xcodeproj/project.pbxproj +++ b/Hydra.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + F876BA7A2919B705005FA746 /* RefreshableScrollView in Frameworks */ = {isa = PBXBuildFile; productRef = F876BA792919B705005FA746 /* RefreshableScrollView */; }; F8875A5C2908867500EE5B98 /* UgentNewsItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8875A5B2908867500EE5B98 /* UgentNewsItem.swift */; }; F8875A5E2908940500EE5B98 /* EntriesResponseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8875A5D2908940500EE5B98 /* EntriesResponseData.swift */; }; F8883AE928EF809D00B71E59 /* Hydra_iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8883AE828EF809D00B71E59 /* Hydra_iOSApp.swift */; }; @@ -17,7 +18,6 @@ F8883B0928EF80AB00B71E59 /* Hydra_iOSUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8883B0828EF80AB00B71E59 /* Hydra_iOSUITests.swift */; }; F8883B0B28EF80AB00B71E59 /* Hydra_iOSUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8883B0A28EF80AB00B71E59 /* Hydra_iOSUITestsLaunchTests.swift */; }; F893240E290747C50023C663 /* NewsItemStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F893240D290747C50023C663 /* NewsItemStorage.swift */; }; - F8959F25290B11890032BBBB /* SwiftUIPullToRefresh in Frameworks */ = {isa = PBXBuildFile; productRef = F8959F24290B11890032BBBB /* SwiftUIPullToRefresh */; }; F8A3BC48290B22AA00210F8E /* NewsEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A3BC47290B22AA00210F8E /* NewsEntry.swift */; }; F8A3BC4A290B27EA00210F8E /* ImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A3BC49290B27EA00210F8E /* ImageLoader.swift */; }; F8A3BC4C290B2A4000210F8E /* URLImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A3BC4B290B2A4000210F8E /* URLImageView.swift */; }; @@ -75,7 +75,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F8959F25290B11890032BBBB /* SwiftUIPullToRefresh in Frameworks */, + F876BA7A2919B705005FA746 /* RefreshableScrollView in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -221,7 +221,7 @@ ); name = Hydra; packageProductDependencies = ( - F8959F24290B11890032BBBB /* SwiftUIPullToRefresh */, + F876BA792919B705005FA746 /* RefreshableScrollView */, ); productName = "Hydra iOS"; productReference = F8883AE528EF809D00B71E59 /* Hydra.app */; @@ -297,7 +297,7 @@ ); mainGroup = F8883ADC28EF809D00B71E59; packageReferences = ( - F8959F23290B11890032BBBB /* XCRemoteSwiftPackageReference "swiftui-pull-to-refresh" */, + F876BA782919B705005FA746 /* XCRemoteSwiftPackageReference "RefreshableScrollView" */, ); productRefGroup = F8883AE628EF809D00B71E59 /* Products */; projectDirPath = ""; @@ -696,21 +696,21 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - F8959F23290B11890032BBBB /* XCRemoteSwiftPackageReference "swiftui-pull-to-refresh" */ = { + F876BA782919B705005FA746 /* XCRemoteSwiftPackageReference "RefreshableScrollView" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/globulus/swiftui-pull-to-refresh"; + repositoryURL = "https://github.com/TariqAlmazyad/RefreshableScrollView.git"; requirement = { - branch = main; - kind = branch; + kind = upToNextMajorVersion; + minimumVersion = 1.0.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - F8959F24290B11890032BBBB /* SwiftUIPullToRefresh */ = { + F876BA792919B705005FA746 /* RefreshableScrollView */ = { isa = XCSwiftPackageProductDependency; - package = F8959F23290B11890032BBBB /* XCRemoteSwiftPackageReference "swiftui-pull-to-refresh" */; - productName = SwiftUIPullToRefresh; + package = F876BA782919B705005FA746 /* XCRemoteSwiftPackageReference "RefreshableScrollView" */; + productName = RefreshableScrollView; }; /* End XCSwiftPackageProductDependency section */