-
Notifications
You must be signed in to change notification settings - Fork 3
[iOS] Add ProgressBar component #75
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
|
Collaborator
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. #question |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Collaborator
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. #question |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Collaborator
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. #question |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Collaborator
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. #question |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Collaborator
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. #question |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| struct ProgressBarProperties: Decodable { | ||
| let text: String? | ||
| let alignment: CraftDAlign? | ||
| let textAlign: CraftDAlign? | ||
| let progressColor: String? | ||
| let textColor: String? | ||
| let progress: Double? | ||
| let height: Double? | ||
| let spaceBetween: Double? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import SwiftUI | ||
|
|
||
| struct CraftDProgressBar: View { | ||
| let text: String | ||
| let textAlign: Alignment | ||
| let alignment: CraftDAlign | ||
| let progressColor: String | ||
| let textColor: String | ||
| let progress: Double | ||
| let height: CGFloat | ||
| let spaceBetween: CGFloat | ||
| let listener: CraftDViewListener | ||
|
|
||
| init( | ||
| _ properties: ProgressBarProperties, | ||
| listener: @escaping CraftDViewListener | ||
| ) { | ||
| self.text = properties.text ?? "" | ||
| self.textAlign = properties.textAlign?.alignment ?? .center | ||
| self.progressColor = properties.progressColor ?? "#0000FF" | ||
| self.progress = properties.progress ?? 0.0 | ||
| self.height = CGFloat(properties.height ?? 0.0) | ||
| self.alignment = properties.alignment ?? .top | ||
| self.textColor = properties.textColor ?? "#000000" | ||
|
Collaborator
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. #question |
||
| self.spaceBetween = properties.spaceBetween ?? 0.0 | ||
| self.listener = listener | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var topAlignmentLayout: some View { | ||
| VStack(spacing: .zero) { | ||
| Text(text) | ||
| .font(.body) | ||
| .foregroundStyle(Color(hex: textColor)) | ||
|
|
||
| GeometryReader { geometry in | ||
| ZStack(alignment: .leading) { | ||
| RoundedRectangle(cornerRadius: 16) | ||
| .stroke(Color.gray.opacity(0.6), lineWidth: 2) | ||
| .fill(Color.clear) | ||
| .frame(height: height) | ||
|
|
||
| RoundedRectangle(cornerRadius: 16) | ||
| .fill(Color(hex: progressColor)) | ||
| .frame(width: geometry.size.width * progress, height: height) | ||
| .animation(.easeInOut, value: progress) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var bottomAlignmentLayout: some View { | ||
| VStack(spacing: .zero) { | ||
|
|
||
| GeometryReader { geometry in | ||
| ZStack(alignment: .leading) { | ||
| RoundedRectangle(cornerRadius: 16) | ||
| .stroke(Color.gray.opacity(0.6), lineWidth: 2) | ||
| .fill(Color.clear) | ||
| .frame(height: height) | ||
|
|
||
| RoundedRectangle(cornerRadius: 16) | ||
| .fill(Color(hex: progressColor)) | ||
| .frame(width: geometry.size.width * progress, height: height) | ||
| .animation(.easeInOut, value: progress) | ||
| } | ||
| } | ||
|
|
||
| Spacer() | ||
| .frame(height: spaceBetween) | ||
|
|
||
| Text(text) | ||
| .font(.body) | ||
| .foregroundStyle(Color(hex: textColor)) | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var leadingAlignmentLayout: some View { | ||
| HStack(alignment: .top, spacing: .zero) { | ||
| Text(text) | ||
| .font(.body) | ||
| .foregroundStyle(Color(hex: textColor)) | ||
|
|
||
| Spacer() | ||
| .frame(width: spaceBetween) | ||
|
|
||
| GeometryReader { geometry in | ||
| ZStack(alignment: .leading) { | ||
| RoundedRectangle(cornerRadius: 16) | ||
| .stroke(Color.gray.opacity(0.6), lineWidth: 2) | ||
| .fill(Color.clear) | ||
| .frame(height: height) | ||
|
|
||
| RoundedRectangle(cornerRadius: 16) | ||
| .fill(Color(hex: progressColor)) | ||
| .frame(width: geometry.size.width * progress, height: height) | ||
| .animation(.easeInOut, value: progress) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var trailingAlignmentLayout: some View { | ||
| HStack(alignment: .top, spacing: .zero) { | ||
|
|
||
| GeometryReader { geometry in | ||
| ZStack(alignment: .leading) { | ||
| RoundedRectangle(cornerRadius: 16) | ||
| .stroke(Color.gray.opacity(0.6), lineWidth: 2) | ||
| .fill(Color.clear) | ||
| .frame(height: height) | ||
|
|
||
| RoundedRectangle(cornerRadius: 16) | ||
| .fill(Color(hex: progressColor)) | ||
| .frame(width: geometry.size.width * progress, height: height) | ||
| .animation(.easeInOut, value: progress) | ||
| } | ||
| } | ||
|
|
||
| Spacer() | ||
| .frame(width: spaceBetween) | ||
|
|
||
| Text(text) | ||
| .font(.body) | ||
| .foregroundStyle(Color(hex: textColor)) | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var content: some View { | ||
| switch alignment { | ||
| case .top, .center: topAlignmentLayout | ||
| case .bottom: bottomAlignmentLayout | ||
| case .left: leadingAlignmentLayout | ||
| case .right: trailingAlignmentLayout | ||
| } | ||
| } | ||
|
|
||
| var body: some View { | ||
| content | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // CraftDProgressBarBuilder.swift | ||
| // CraftDSwiftUI | ||
| // | ||
| // Created by Pedro Alvarez on 17/11/25. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| class CraftDProgressBarBuilder: CraftDBuilder { | ||
| public func craft(model: SimpleProperties, listener: @escaping CraftDViewListener) -> any View { | ||
| do { | ||
| let properties = try model.decodeValue(ProgressBarProperties.self, using: decoder) | ||
| return CraftDProgressBar(properties, listener: listener) | ||
| } catch { | ||
| return EmptyView() | ||
| } | ||
| } | ||
| } |
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.
#question
Can you remove this file? It is not necessary