diff --git a/Xcodes/Frontend/Common/ProgressButton.swift b/Xcodes/Frontend/Common/ProgressButton.swift index 2b6668d..34b6f6e 100644 --- a/Xcodes/Frontend/Common/ProgressButton.swift +++ b/Xcodes/Frontend/Common/ProgressButton.swift @@ -21,13 +21,17 @@ struct ProgressButton: 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) } diff --git a/Xcodes/Frontend/XcodeList/MainToolbar.swift b/Xcodes/Frontend/XcodeList/MainToolbar.swift index 3ea81d6..1c60822 100644 --- a/Xcodes/Frontend/XcodeList/MainToolbar.swift +++ b/Xcodes/Frontend/XcodeList/MainToolbar.swift @@ -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 {