Use ProgressButton in MainToolbar

Made a small change to how ProgressButton is constructed to prevent its frame changing when isInProgress changes.
This commit is contained in:
Brandon Evans 2020-12-28 11:57:45 -07:00
parent 4cb60e2929
commit 09653b7357
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
2 changed files with 15 additions and 15 deletions

View file

@ -21,13 +21,17 @@ struct ProgressButton<Label: View>: View {
var body: some View {
Button(action: action) {
if isInProgress {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
} else {
label()
}
// This might look like a strange way to switch between the label and the progress view.
// Doing it this way, so that the label is hidden but still has the same frame and is in the view hierarchy
// makes sure that the button's frame doesn't change when isInProgress changes.
label()
.isHidden(isInProgress)
.overlay(
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
.isHidden(!isInProgress)
)
}
.disabled(isInProgress)
}

View file

@ -12,17 +12,13 @@ struct MainToolbarModifier: ViewModifier {
private var toolbar: some ToolbarContent {
ToolbarItemGroup(placement: .status) {
Button(action: appState.update) {
ProgressButton(
isInProgress: appState.isUpdating,
action: appState.update
) {
Label("Refresh", systemImage: "arrow.clockwise")
}
.keyboardShortcut(KeyEquivalent("r"))
.disabled(appState.isUpdating)
.isHidden(appState.isUpdating)
.overlay(
ProgressView()
.scaleEffect(0.5, anchor: .center)
.isHidden(!appState.isUpdating)
)
Button(action: {
switch category {