Skip to content

Commit

Permalink
feat: add pull to refresh on lists
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 8, 2021
1 parent b69e0a5 commit 8953b37
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
17 changes: 17 additions & 0 deletions firstfm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
82D5B4D22696DBD700716931 /* ScrobblesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D5B4D12696DBD700716931 /* ScrobblesViewModel.swift */; };
82D5B4D42696DC7800716931 /* RecentTracks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D5B4D32696DC7800716931 /* RecentTracks.swift */; };
82D5B4D62696E0E100716931 /* ScrobbledTrackRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D5B4D52696E0E100716931 /* ScrobbledTrackRowView.swift */; };
82E80C39269777C60098DC3C /* SwiftUIRefresh in Frameworks */ = {isa = PBXBuildFile; productRef = 82E80C38269777C60098DC3C /* SwiftUIRefresh */; };
82FBAE472674B8FC000D8E29 /* Artist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FBAE462674B8FC000D8E29 /* Artist.swift */; };
82FBAE492674BB55000D8E29 /* ChartViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FBAE482674BB55000D8E29 /* ChartViewModel.swift */; };
82FBAE4C2674BCB7000D8E29 /* ArtistResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FBAE4B2674BCB7000D8E29 /* ArtistResponse.swift */; };
Expand Down Expand Up @@ -86,6 +87,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
82E80C39269777C60098DC3C /* SwiftUIRefresh in Frameworks */,
82505CE42675178B00CCCB58 /* Kingfisher in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -233,6 +235,7 @@
name = firstfm;
packageProductDependencies = (
82505CE32675178B00CCCB58 /* Kingfisher */,
82E80C38269777C60098DC3C /* SwiftUIRefresh */,
);
productName = firstfm;
productReference = 82844DFD2673991F00578DD4 /* firstfm.app */;
Expand Down Expand Up @@ -263,6 +266,7 @@
mainGroup = 82844DF42673991F00578DD4;
packageReferences = (
82505CE22675178B00CCCB58 /* XCRemoteSwiftPackageReference "Kingfisher" */,
82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */,
);
productRefGroup = 82844DFE2673991F00578DD4 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -523,6 +527,14 @@
minimumVersion = 6.3.0;
};
};
82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/timbersoftware/SwiftUIRefresh.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.3;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -531,6 +543,11 @@
package = 82505CE22675178B00CCCB58 /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher;
};
82E80C38269777C60098DC3C /* SwiftUIRefresh */ = {
isa = XCSwiftPackageProductDependency;
package = 82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */;
productName = SwiftUIRefresh;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 82844DF52673991F00578DD4 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
"revision": "44450a8f564d7c0165f736ba2250649ff8d3e556",
"version": "6.3.0"
}
},
{
"package": "Introspect",
"repositoryURL": "https://github.com/siteline/SwiftUI-Introspect.git",
"state": {
"branch": null,
"revision": "2e09be8af614401bc9f87d40093ec19ce56ccaf2",
"version": "0.1.3"
}
},
{
"package": "SwiftUIRefresh",
"repositoryURL": "https://github.com/timbersoftware/SwiftUIRefresh.git",
"state": {
"branch": null,
"revision": "fa8fac7b5eb5c729983a8bef65f094b5e0d12014",
"version": "0.0.3"
}
}
]
},
Expand Down
9 changes: 9 additions & 0 deletions firstfm/Views/ChartListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct ChartList: View {
@State var artistsLoaded = false
@State var tracksLoaded = false
@State private var selectedChartsIndex = 0
@State private var isPullLoaderShowing = false

var body: some View {
NavigationView {
Expand Down Expand Up @@ -47,6 +48,10 @@ struct ChartList: View {
self.artistsLoaded = true
}
}
.pullToRefresh(isShowing: $isPullLoaderShowing) {
self.charts.getChartingArtists()
self.isPullLoaderShowing = false
}
}
if selectedChartsIndex == 1 {
List(charts.tracks) { track in
Expand All @@ -62,6 +67,10 @@ struct ChartList: View {
self.tracksLoaded = true
}
}
.pullToRefresh(isShowing: $isPullLoaderShowing) {
self.charts.getChartingTracks()
self.isPullLoaderShowing = false
}
}


Expand Down
10 changes: 8 additions & 2 deletions firstfm/Views/ScrobblesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
//

import SwiftUI
import SwiftUIRefresh

struct Scrobbles: View {
@ObservedObject var vm = ScrobblesViewModel()
@State var scrobblesLoaded = false
@State private var selectedChartsIndex = 0
@State private var isPullLoaderShowing = false

var body: some View {
NavigationView {
Expand All @@ -20,15 +22,19 @@ struct Scrobbles: View {
NavigationLink(
destination: Color(.blue),
label: {
ScrobbledTrackRow(track: track)
})
ScrobbledTrackRow(track: track)
})
}.navigationTitle("Scrobbles").onAppear {
if !scrobblesLoaded {
vm.getUserScrobbles()
// Prevent loading again when navigating
scrobblesLoaded = true
}
}
.pullToRefresh(isShowing: $isPullLoaderShowing) {
vm.getUserScrobbles()
self.isPullLoaderShowing = false
}
}
// Show loader above the rest of the ZStack
if vm.isLoading {
Expand Down

0 comments on commit 8953b37

Please sign in to comment.