mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
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:
parent
4cb60e2929
commit
09653b7357
2 changed files with 15 additions and 15 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue