@@ -4,6 +4,7 @@ public struct ProgressView<Label: View>: View {
44 private var label : Label
55 private var progress : Double ?
66 private var kind : Kind
7+ private var isSpinnerResizable : Bool = false
78
89 private enum Kind {
910 case spinner
@@ -23,7 +24,7 @@ public struct ProgressView<Label: View>: View {
2324 private var progressIndicator : some View {
2425 switch kind {
2526 case . spinner:
26- ProgressSpinnerView ( )
27+ ProgressSpinnerView ( isResizable : isSpinnerResizable )
2728 case . bar:
2829 ProgressBarView ( value: progress)
2930 }
@@ -50,6 +51,25 @@ public struct ProgressView<Label: View>: View {
5051 self . kind = . bar
5152 self . progress = value. map ( Double . init)
5253 }
54+
55+ /// Used to make a copy with applied changes.
56+ private init (
57+ label: Label ,
58+ _ progress: Double ? ,
59+ kind: Kind ,
60+ isSpinnerResizable: Bool
61+ ) {
62+ self . label = label
63+ self . progress = progress
64+ self . kind = kind
65+ self . isSpinnerResizable = isSpinnerResizable
66+ }
67+
68+ /// Makes the ProgressView resizable.
69+ /// Only affects `Kind.spinner`.
70+ public func resizable( _ isResizable: Bool = true ) -> Self {
71+ Self ( label: label, progress, kind: kind, isSpinnerResizable: isResizable)
72+ }
5373}
5474
5575extension ProgressView where Label == EmptyView {
@@ -101,7 +121,10 @@ extension ProgressView where Label == Text {
101121}
102122
103123struct ProgressSpinnerView : ElementaryView {
104- init ( ) { }
124+ let isResizable : Bool
125+ init ( isResizable: Bool = false ) {
126+ self . isResizable = isResizable
127+ }
105128
106129 func asWidget< Backend: AppBackend > ( backend: Backend ) -> Backend . Widget {
107130 backend. createProgressSpinner ( )
@@ -115,6 +138,12 @@ struct ProgressSpinnerView: ElementaryView {
115138 dryRun: Bool
116139 ) -> ViewUpdateResult {
117140 let naturalSize = backend. naturalSize ( of: widget)
141+ guard isResizable else {
142+ // Required to reset its size when resizability
143+ // gets changed at runtime
144+ backend. setSize ( of: widget, to: naturalSize)
145+ return ViewUpdateResult . leafView ( size: ViewSize ( fixedSize: naturalSize) )
146+ }
118147 let min = max ( min ( proposedSize. x, proposedSize. y) , 10 )
119148 let size = SIMD2 (
120149 min,
0 commit comments