Implement refresh progress bar for macOS
This commit is contained in:
parent
69fa598d99
commit
46762bf297
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// RefreshProgressView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Phil Viso on 7/2/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RefreshProgressView: View {
|
||||
|
||||
@EnvironmentObject private var refreshProgress: RefreshProgressModel
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
switch refreshProgress.state {
|
||||
case .refreshProgress(let progress):
|
||||
ProgressView(value: progress)
|
||||
.frame(width: progressViewWidth())
|
||||
case .lastRefreshDateText(let text):
|
||||
Text(text)
|
||||
.lineLimit(1)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
case .none:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK -
|
||||
|
||||
private func progressViewWidth() -> CGFloat {
|
||||
#if os(macOS)
|
||||
return 40.0
|
||||
#else
|
||||
return 100.0
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import SwiftUI
|
|||
|
||||
struct SidebarToolbarModifier: ViewModifier {
|
||||
|
||||
@EnvironmentObject private var refreshProgress: RefreshProgressModel
|
||||
@EnvironmentObject private var defaults: AppDefaults
|
||||
@EnvironmentObject private var sidebarModel: SidebarModel
|
||||
@StateObject private var viewModel = SidebarToolbarModel()
|
||||
|
@ -48,7 +49,18 @@ struct SidebarToolbarModifier: ViewModifier {
|
|||
}
|
||||
|
||||
ToolbarItem(placement: .automatic) {
|
||||
RefreshProgressView()
|
||||
switch refreshProgress.state {
|
||||
case .refreshProgress(let progress):
|
||||
ProgressView(value: progress)
|
||||
.frame(width: 100)
|
||||
case .lastRefreshDateText(let text):
|
||||
Text(text)
|
||||
.lineLimit(1)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
case .none:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
|
|
|
@ -14,6 +14,7 @@ struct SidebarView: View {
|
|||
// I had to comment out SceneStorage because it blows up if used on macOS
|
||||
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
|
||||
@StateObject private var expandedContainers = SidebarExpandedContainers()
|
||||
@EnvironmentObject private var refreshProgress: RefreshProgressModel
|
||||
@EnvironmentObject private var sceneModel: SceneModel
|
||||
@EnvironmentObject private var sidebarModel: SidebarModel
|
||||
@State var navigate = false
|
||||
|
@ -21,8 +22,9 @@ struct SidebarView: View {
|
|||
private let threshold: CGFloat = 80
|
||||
@State private var previousScrollOffset: CGFloat = 0
|
||||
@State private var scrollOffset: CGFloat = 0
|
||||
@State var pulling: Bool = false
|
||||
@State var refreshing: Bool = false
|
||||
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
#if os(macOS)
|
||||
VStack {
|
||||
|
@ -43,13 +45,25 @@ struct SidebarView: View {
|
|||
.buttonStyle(PlainButtonStyle())
|
||||
.help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds")
|
||||
}
|
||||
ZStack {
|
||||
ZStack(alignment: .bottom) {
|
||||
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), isActive: $navigate) {
|
||||
EmptyView()
|
||||
}.hidden()
|
||||
List(selection: $sidebarModel.selectedFeedIdentifiers) {
|
||||
rows
|
||||
}
|
||||
if case .refreshProgress(let percent) = refreshProgress.state {
|
||||
HStack(alignment: .center) {
|
||||
Spacer()
|
||||
ProgressView(value: percent).frame(width: 100)
|
||||
Spacer()
|
||||
}
|
||||
.padding(8)
|
||||
.background(Color(NSColor.windowBackgroundColor))
|
||||
.frame(height: 30)
|
||||
.animation(.easeInOut(duration: 0.5))
|
||||
.transition(.move(edge: .bottom))
|
||||
}
|
||||
}
|
||||
.onChange(of: sidebarModel.selectedFeedIdentifiers) { value in
|
||||
navigate = !sidebarModel.selectedFeedIdentifiers.isEmpty
|
||||
|
@ -65,7 +79,7 @@ struct SidebarView: View {
|
|||
.onPreferenceChange(RefreshKeyTypes.PrefKey.self) { values in
|
||||
refreshLogic(values: values)
|
||||
}
|
||||
if refreshing {
|
||||
if pulling {
|
||||
ProgressView().offset(y: -40)
|
||||
}
|
||||
}
|
||||
|
@ -85,14 +99,14 @@ struct SidebarView: View {
|
|||
scrollOffset = movingBounds.minY - fixedBounds.minY
|
||||
|
||||
// Crossing the threshold on the way down, we start the refresh process
|
||||
if !refreshing && (scrollOffset > threshold && previousScrollOffset <= threshold) {
|
||||
refreshing = true
|
||||
if !pulling && (scrollOffset > threshold && previousScrollOffset <= threshold) {
|
||||
pulling = true
|
||||
AccountManager.shared.refreshAll(errorHandler: handleRefreshError)
|
||||
}
|
||||
|
||||
// Crossing the threshold on the way UP, we end the refresh
|
||||
if refreshing && previousScrollOffset > threshold && scrollOffset <= threshold {
|
||||
refreshing = false
|
||||
if pulling && previousScrollOffset > threshold && scrollOffset <= threshold {
|
||||
pulling = false
|
||||
}
|
||||
|
||||
// Update last scroll offset
|
||||
|
|
|
@ -1104,8 +1104,6 @@
|
|||
FF3ABF162325AF5D0074C542 /* ArticleSorter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF3ABF1423259DDB0074C542 /* ArticleSorter.swift */; };
|
||||
FF64D0E724AF53EE0084080A /* RefreshProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF64D0C424AF53EE0084080A /* RefreshProgressModel.swift */; };
|
||||
FF64D0E824AF53EE0084080A /* RefreshProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF64D0C424AF53EE0084080A /* RefreshProgressModel.swift */; };
|
||||
FF64D0E924AF53EE0084080A /* RefreshProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF64D0E624AF53EE0084080A /* RefreshProgressView.swift */; };
|
||||
FF64D0EA24AF53EE0084080A /* RefreshProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF64D0E624AF53EE0084080A /* RefreshProgressView.swift */; };
|
||||
FFD43E412340F488009E5CA3 /* MarkAsReadAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD43E372340F320009E5CA3 /* MarkAsReadAlertController.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
@ -2357,7 +2355,6 @@
|
|||
FF3ABF09232599450074C542 /* ArticleSorterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleSorterTests.swift; sourceTree = "<group>"; };
|
||||
FF3ABF1423259DDB0074C542 /* ArticleSorter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleSorter.swift; sourceTree = "<group>"; };
|
||||
FF64D0C424AF53EE0084080A /* RefreshProgressModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshProgressModel.swift; sourceTree = "<group>"; };
|
||||
FF64D0E624AF53EE0084080A /* RefreshProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshProgressView.swift; sourceTree = "<group>"; };
|
||||
FFD43E372340F320009E5CA3 /* MarkAsReadAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkAsReadAlertController.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -3220,7 +3217,6 @@
|
|||
51E499FB24A9135A00B667CB /* Sidebar */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FF64D0E624AF53EE0084080A /* RefreshProgressView.swift */,
|
||||
51E499FF24A91FC100B667CB /* SidebarContainerView.swift */,
|
||||
51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */,
|
||||
51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */,
|
||||
|
@ -4255,46 +4251,46 @@
|
|||
TargetAttributes = {
|
||||
51314636235A7BBE00387FDC = {
|
||||
CreatedOnToolsVersion = 11.2;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
LastSwiftMigration = 1120;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
513C5CE5232571C2003D4054 = {
|
||||
CreatedOnToolsVersion = 11.0;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
518B2ED12351B3DD00400001 = {
|
||||
CreatedOnToolsVersion = 11.2;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
TestTargetID = 840D617B2029031C009BC708;
|
||||
};
|
||||
51C0513C24A77DF800194D5E = {
|
||||
CreatedOnToolsVersion = 12.0;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
51C0514324A77DF800194D5E = {
|
||||
CreatedOnToolsVersion = 12.0;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
6581C73220CED60000F4AD34 = {
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
65ED3FA2235DEF6C0081F399 = {
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
65ED4090235DEF770081F399 = {
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
840D617B2029031C009BC708 = {
|
||||
CreatedOnToolsVersion = 9.3;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
SystemCapabilities = {
|
||||
com.apple.BackgroundModes = {
|
||||
|
@ -4304,7 +4300,7 @@
|
|||
};
|
||||
849C645F1ED37A5D003D8FC0 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
SystemCapabilities = {
|
||||
com.apple.HardenedRuntime = {
|
||||
|
@ -4314,7 +4310,7 @@
|
|||
};
|
||||
849C64701ED37A5D003D8FC0 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = FQLBNX3GP7;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
ProvisioningStyle = Automatic;
|
||||
TestTargetID = 849C645F1ED37A5D003D8FC0;
|
||||
};
|
||||
|
@ -5152,7 +5148,6 @@
|
|||
51E49A0324A91FF600B667CB /* SceneNavigationView.swift in Sources */,
|
||||
51E4990124A808BB00B667CB /* FaviconURLFinder.swift in Sources */,
|
||||
51E4991D24A8092100B667CB /* NSAttributedString+NetNewsWire.swift in Sources */,
|
||||
FF64D0E924AF53EE0084080A /* RefreshProgressView.swift in Sources */,
|
||||
6591720E24B59C5100B638E8 /* SettingsFeedbinAccountModel.swift in Sources */,
|
||||
51E499FD24A9137600B667CB /* SidebarModel.swift in Sources */,
|
||||
5181C66224B0C326002E0F70 /* SettingsModel.swift in Sources */,
|
||||
|
@ -5355,7 +5350,6 @@
|
|||
51E4992D24A8676300B667CB /* FetchRequestOperation.swift in Sources */,
|
||||
51E4992424A8098400B667CB /* SmartFeedPasteboardWriter.swift in Sources */,
|
||||
51E4991424A808FF00B667CB /* ArticleStringFormatter.swift in Sources */,
|
||||
FF64D0EA24AF53EE0084080A /* RefreshProgressView.swift in Sources */,
|
||||
51B54A6624B549CB0014348B /* PreloadedWebView.swift in Sources */,
|
||||
51E4991024A808DE00B667CB /* SmallIconProvider.swift in Sources */,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue