-
-
Notifications
You must be signed in to change notification settings - Fork 59
Fix/progess spinner resizing #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ba361de
660f678
6879d40
c3bc981
4645c19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ public struct ProgressView<Label: View>: View { | |
| private var label: Label | ||
| private var progress: Double? | ||
| private var kind: Kind | ||
| private var isSpinnerResizable: Bool = false | ||
|
|
||
| private enum Kind { | ||
| case spinner | ||
|
|
@@ -23,7 +24,7 @@ public struct ProgressView<Label: View>: View { | |
| private var progressIndicator: some View { | ||
| switch kind { | ||
| case .spinner: | ||
| ProgressSpinnerView() | ||
| ProgressSpinnerView(isResizable: isSpinnerResizable) | ||
| case .bar: | ||
| ProgressBarView(value: progress) | ||
| } | ||
|
|
@@ -50,6 +51,14 @@ public struct ProgressView<Label: View>: View { | |
| self.kind = .bar | ||
| self.progress = value.map(Double.init) | ||
| } | ||
|
|
||
| /// Makes the ProgressView resize to fit the available space. | ||
| /// Only affects `Kind.spinner`. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the reference to so that it links through. |
||
| public func resizable(_ isResizable: Bool = true) -> Self { | ||
| var progressView = self | ||
| progressView.isSpinnerResizable = isResizable | ||
| return progressView | ||
| } | ||
| } | ||
|
|
||
| extension ProgressView where Label == EmptyView { | ||
|
|
@@ -101,7 +110,10 @@ extension ProgressView where Label == Text { | |
| } | ||
|
|
||
| struct ProgressSpinnerView: ElementaryView { | ||
| init() {} | ||
| let isResizable: Bool | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And blank line after this var |
||
| init(isResizable: Bool = false) { | ||
| self.isResizable = isResizable | ||
| } | ||
|
|
||
| func asWidget<Backend: AppBackend>(backend: Backend) -> Backend.Widget { | ||
| backend.createProgressSpinner() | ||
|
|
@@ -114,8 +126,33 @@ struct ProgressSpinnerView: ElementaryView { | |
| backend: Backend, | ||
| dryRun: Bool | ||
| ) -> ViewUpdateResult { | ||
| ViewUpdateResult.leafView( | ||
| size: ViewSize(fixedSize: backend.naturalSize(of: widget)) | ||
| let naturalSize = backend.naturalSize(of: widget) | ||
| guard isResizable else { | ||
| // Required to reset its size when resizability | ||
| // gets changed at runtime | ||
| backend.setSize(of: widget, to: naturalSize) | ||
| return ViewUpdateResult.leafView(size: ViewSize(fixedSize: naturalSize)) | ||
| } | ||
| let min = max(min(proposedSize.x, proposedSize.y), 10) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to have a lower bound of 10? I feel like we should just let the spinner vanish to 0 by 0 if sufficiently squished (like we do for other resizable views such as images or shapes). 10 is also backend-specific, so may not be a suitable minimum for all backends. |
||
| let size = SIMD2( | ||
| min, | ||
| min | ||
| ) | ||
| if !dryRun { | ||
| // Doesn't change the rendered size of ProgressSpinner | ||
| // on UIKitBackend, but still sets container size to | ||
| // (width: n, height: n) n = min(proposedSize.x, proposedSize.y) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this centre the spinner in the proposed frame under UIKitBackend? |
||
| backend.setSize(of: widget, to: size) | ||
| } | ||
| return ViewUpdateResult.leafView( | ||
| size: ViewSize( | ||
| size: size, | ||
| idealSize: naturalSize, | ||
| minimumWidth: 10, | ||
| minimumHeight: 10, | ||
|
Comment on lines
+151
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set these to zero after applying the above feedback for the |
||
| maximumWidth: nil, | ||
| maximumHeight: nil | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this blank line