From c237ff24c4c323b8d73084721faf7f18ad94293f Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Mon, 2 Sep 2024 10:22:58 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[JIRA:HCPSDKFIORIUIK?= =?UTF-8?q?IT-2716]Step=20Progress=20Indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add stepProgressIndicatorNodeType for step node. --- .../StepProgressIndicatorExample.swift | 1 + .../StepProgressIndicator/StepItem.swift | 10 ++++++++++ .../StepsEnvironment.swift | 20 +++++++++++++++++++ .../StepProgressIndicator/_DefaultSteps.swift | 19 +++++++++++++++--- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift index bfed3ef30..f13f82cad 100644 --- a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift +++ b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift @@ -79,6 +79,7 @@ struct SPIExampleWithIcon: View { } } } + .stepProgressIndicatorNodeType(.icon) Spacer().padding(20) Button { self.completeStep() diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift index 10dd8ef99..eefb134af 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift @@ -14,3 +14,13 @@ public protocol StepItem { /// Node icon. var icon: Image? { get } } + +/// Node of Step Progress Indicator display type, default is `mixture`. +public enum StepProgressIndicatorNodeType { + /// Text and icon. + case mixture + /// Only text. + case text + /// Only icon. + case icon +} diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift index d7f7a8a1b..deca31e49 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift @@ -22,6 +22,26 @@ extension EnvironmentValues { } } +struct StepProgressIndicatorNodeTypeKey: EnvironmentKey { + static let defaultValue: StepProgressIndicatorNodeType = .mixture +} + +extension EnvironmentValues { + var stepProgressIndicatorNodeType: StepProgressIndicatorNodeType { + get { self[StepProgressIndicatorNodeTypeKey.self] } + set { self[StepProgressIndicatorNodeTypeKey.self] = newValue } + } +} + +public extension View { + /// The style of the node of `StepProgressIndicator`. + /// - Parameter type: `StepProgressIndicatorNodeType` enum values. + /// - Returns: A new `StepProgressIndicator` with specific node. + func stepProgressIndicatorNodeType(_ type: StepProgressIndicatorNodeType) -> some View { + self.environment(\.stepProgressIndicatorNodeType, type) + } +} + public extension View { /// Step style for `StepProgressIndicator`. /// - Parameter style: Style for `StepProgressIndicator`. diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index f8a571c5f..996da677f 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -52,6 +52,7 @@ struct DefaultSingleStep: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize @Environment(\.stepAxis) var stepAxis @Environment(\.stepFrames) var stepFrames + @Environment(\.stepProgressIndicatorNodeType) var type var stepItem: StepItem @Binding var selection: String @@ -98,11 +99,23 @@ struct DefaultSingleStep: View { } node: { ZStack { self.node(by: self.stepItem.state, isSelected: isSelected) - if self.stepItem.icon.isEmpty { + switch self.type { + case .mixture: + if self.stepItem.icon.isEmpty { + Text("\(self.index + 1)") + .font(Font.fiori(forTextStyle: .footnote)) + } else { + self.stepItem.icon + } + case .icon: + if self.stepItem.icon.isEmpty { + Image(systemName: "app.dashed") + } else { + self.stepItem.icon + } + case .text: Text("\(self.index + 1)") .font(Font.fiori(forTextStyle: .footnote)) - } else { - self.stepItem.icon } } .frame(width: self.sideLength, height: self.sideLength) From 8bfddc15fa9ac65dd30bb9e9130157549af5e5c7 Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Thu, 5 Sep 2024 13:36:03 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[JIRA:HCPSDKFIORIUIK?= =?UTF-8?q?IT-2716]Step=20Progress=20Indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use TextOrIcon replace Image --- .../StepProgressIndicatorExample.swift | 98 +++++++++++++------ .../StepProgressIndicator/StepItem.swift | 4 +- .../StepProgressIndicator/_DefaultSteps.swift | 41 ++++++-- 3 files changed, 99 insertions(+), 44 deletions(-) diff --git a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift index f13f82cad..c0986c815 100644 --- a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift +++ b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift @@ -51,27 +51,42 @@ struct StepProgressIndicatorExample_Previews: PreviewProvider { } struct SPIExampleWithIcon: View { - static let icon = Image(systemName: "app.dashed") @State var title: String = "" - @State var steps = [StepItemData(title: "Sign In", icon: FioriIcon.arrows.initiative, state: .completed), - StepItemData(title: "User Info", icon: FioriIcon.people.personPlaceholder, state: .completed), - StepItemData(title: "Account Info", icon: FioriIcon.actions.edit, state: .completed), - StepItemData(title: "Settings", icon: FioriIcon.actions.actionSettings, state: .normal, substeps: [StepItemData(title: "Settings 1")]), - StepItemData(title: "Other0", icon: icon, state: .disabled), - StepItemData(title: "Other1", icon: icon, state: .completed), - StepItemData(title: "other2", icon: icon, state: .error)] - @State var selection: String = "" + @State var iconSteps = [StepItemData(title: "Sign In", node: .icon(FioriIcon.arrows.initiative), state: .completed), + StepItemData(title: "User Info", node: .icon(FioriIcon.people.personPlaceholder), state: .completed), + StepItemData(title: "Account Info", node: .icon(FioriIcon.actions.edit), state: .completed), + StepItemData(title: "Settings", node: .icon(FioriIcon.actions.actionSettings), state: .normal, substeps: [StepItemData(title: "Settings 1")]), + StepItemData(title: "Other0", state: .disabled), + StepItemData(title: "Other1", state: .completed), + StepItemData(title: "other2", state: .error)] + @State var mixtureSteps = [StepItemData(title: "Sign In", node: .text("No.1"), state: .completed), + StepItemData(title: "User Info", state: .completed), + StepItemData(title: "Account Info", node: .icon(FioriIcon.actions.edit), state: .completed), + StepItemData(title: "Settings", node: .icon(FioriIcon.actions.actionSettings), state: .normal, substeps: [StepItemData(title: "Settings 1")]), + StepItemData(title: "Other0", state: .disabled), + StepItemData(title: "Other1", state: .completed), + StepItemData(title: "other2", state: .error)] + @State var textSteps = [StepItemData(title: "Sign In", state: .completed), + StepItemData(title: "User Info", node: .text("AB"), state: .completed), + StepItemData(title: "Account Info", state: .completed), + StepItemData(title: "Settings", node: .text("AD"), state: .normal, substeps: [StepItemData(title: "Settings 1")]), + StepItemData(title: "Other0", state: .disabled), + StepItemData(title: "Other1", state: .completed), + StepItemData(title: "other2", state: .error)] + @State var iconSelection: String = "" + @State var mixtureSelection: String = "" + @State var textSelection: String = "" var body: some View { VStack(alignment: .leading) { - Text("Icon").bold() - StepProgressIndicator(selection: self.$selection, - stepItems: self.steps) + Text("Step: Only Icon Node").bold() + StepProgressIndicator(selection: self.$iconSelection, + stepItems: self.iconSteps) { Text(self.$title.wrappedValue).lineLimit(1) } action: { Button {} label: { HStack(spacing: 2) { - Text("All Steps(\(self.steps.count))") + Text("All Steps(\(self.iconSteps.count))") .foregroundStyle(Color.preferredColor(.tintColor)) FioriIcon.actions.slimArrowRight .font(.fiori(forTextStyle: .subheadline, weight: .semibold)) @@ -80,6 +95,32 @@ struct SPIExampleWithIcon: View { } } .stepProgressIndicatorNodeType(.icon) + .padding() + .onChange(of: self.iconSelection, perform: { _ in + self.updateCurrentStepName() + }) + .onAppear { + self.updateCurrentStepName() + } + + Text("Step: Mixture Node").bold() + StepProgressIndicator(selection: self.$mixtureSelection, + stepItems: self.mixtureSteps) + { + Text("Invariant title").lineLimit(1) + } action: {} + .stepProgressIndicatorNodeType(.mixture) + .padding() + + Text("Step: Only Text Node").bold() + StepProgressIndicator(selection: self.$textSelection, + stepItems: self.textSteps) + { + Text("Invariant title").lineLimit(1) + } action: {} + .stepProgressIndicatorNodeType(.text) + .padding() + Spacer().padding(20) Button { self.completeStep() @@ -88,19 +129,12 @@ struct SPIExampleWithIcon: View { } .padding(20) } - .padding() - .onChange(of: self.selection, perform: { _ in - self.updateCurrentStepName() - }) - .onAppear { - self.updateCurrentStepName() - } } func getStep() -> StepItem? { func findStep(in data: [StepItem]) -> StepItem? { for step in data { - if step.id == self.selection { + if step.id == self.iconSelection { return step } @@ -115,7 +149,7 @@ struct SPIExampleWithIcon: View { return nil } - return findStep(in: self.steps) + return findStep(in: self.iconSteps) } func updateCurrentStepName() { @@ -126,15 +160,15 @@ struct SPIExampleWithIcon: View { } func completeStep() { - for index in self.steps.indices { - if self.steps[index].id == self.selection { - self.steps[index].state = .completed + for index in self.iconSteps.indices { + if self.iconSteps[index].id == self.iconSelection { + self.iconSteps[index].state = .completed } else { - let substeps = self.steps[index].substeps + let substeps = self.iconSteps[index].substeps guard !substeps.isEmpty else { continue } for subindex in substeps.indices { - if substeps[subindex].id == self.selection { - self.steps[index].substeps[subindex].state = .completed + if substeps[subindex].id == self.iconSelection { + self.iconSteps[index].substeps[subindex].state = .completed } } } @@ -529,8 +563,8 @@ struct StepItemData: StepItem { var id: String = UUID().uuidString /// Step title. var title: String? - /// Node icon - var icon: Image? + /// Step node + var node: TextOrIcon? /// Step state. var state: StepProgressIndicatorState = .normal /// Sub-steps for this one. @@ -538,13 +572,13 @@ struct StepItemData: StepItem { init(id: String = UUID().uuidString, title: String? = nil, - icon: Image? = nil, + node: TextOrIcon? = nil, state: StepProgressIndicatorState = [], substeps: [StepItemData] = []) { self.id = id self.title = title - self.icon = icon + self.node = node self.state = state self.substeps = substeps } diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift index eefb134af..dd3d14a39 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift @@ -11,8 +11,8 @@ public protocol StepItem { var state: StepProgressIndicatorState { get set } /// Substeps for this one. var substeps: [StepItem] { get set } - /// Node icon. - var icon: Image? { get } + /// Step node. + var node: TextOrIcon? { get } } /// Node of Step Progress Indicator display type, default is `mixture`. diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index 996da677f..de0038002 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -1,3 +1,4 @@ +import FioriThemeManager import SwiftUI /// Not used by developers. @@ -99,23 +100,30 @@ struct DefaultSingleStep: View { } node: { ZStack { self.node(by: self.stepItem.state, isSelected: isSelected) + self.noNodeStep() switch self.type { case .mixture: - if self.stepItem.icon.isEmpty { - Text("\(self.index + 1)") + switch self.stepItem.node { + case .text(let string): + Text(string) .font(Font.fiori(forTextStyle: .footnote)) - } else { - self.stepItem.icon + case .icon(let image): image + case .none: EmptyView() } case .icon: - if self.stepItem.icon.isEmpty { - Image(systemName: "app.dashed") - } else { - self.stepItem.icon + switch self.stepItem.node { + case .icon(let image): + image + case .none, .text: EmptyView() } case .text: - Text("\(self.index + 1)") - .font(Font.fiori(forTextStyle: .footnote)) + switch self.stepItem.node { + case .text(let string): + Text(string) + .font(Font.fiori(forTextStyle: .footnote)) + case .icon, .none: + EmptyView() + } } } .frame(width: self.sideLength, height: self.sideLength) @@ -139,6 +147,19 @@ struct DefaultSingleStep: View { } } + @ViewBuilder + func noNodeStep() -> some View { + if self.stepItem.node == nil { + switch self.type { + case .mixture, .text: + Text("\(self.index + 1)") + .font(Font.fiori(forTextStyle: .footnote)) + case .icon: + Image(systemName: "app.dashed") + } + } + } + @ViewBuilder func singleSubstep() -> some View { if self.stepItem.state.isSupported { From a41733a1778c9f6296fc63cd84cb0999366a1611 Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Thu, 5 Sep 2024 14:03:04 +0800 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[JIRA:HCPSDKFIORIUIK?= =?UTF-8?q?IT-2716]Step=20Progress=20Indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit code format --- .../Views/StepProgressIndicator/_DefaultSteps.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index de0038002..8c9ba4a81 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -107,14 +107,17 @@ struct DefaultSingleStep: View { case .text(let string): Text(string) .font(Font.fiori(forTextStyle: .footnote)) - case .icon(let image): image - case .none: EmptyView() + case .icon(let image): + image + case .none: + EmptyView() } case .icon: switch self.stepItem.node { case .icon(let image): image - case .none, .text: EmptyView() + case .none, .text: + EmptyView() } case .text: switch self.stepItem.node { From da09ec266af855227236fd7d3ed71c69a420f2ec Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Mon, 9 Sep 2024 10:18:16 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[JIRA:HCPSDKFIORIUIK?= =?UTF-8?q?IT-2716]Step=20Progress=20Indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the mixture property of StepProgressIndicatorNodeType. --- .../StepProgressIndicatorExample.swift | 17 ----------------- .../Views/StepProgressIndicator/StepItem.swift | 4 +--- .../StepsEnvironment.swift | 2 +- .../StepProgressIndicator/_DefaultSteps.swift | 12 +----------- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift index c0986c815..2fe46da1b 100644 --- a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift +++ b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift @@ -59,13 +59,6 @@ struct SPIExampleWithIcon: View { StepItemData(title: "Other0", state: .disabled), StepItemData(title: "Other1", state: .completed), StepItemData(title: "other2", state: .error)] - @State var mixtureSteps = [StepItemData(title: "Sign In", node: .text("No.1"), state: .completed), - StepItemData(title: "User Info", state: .completed), - StepItemData(title: "Account Info", node: .icon(FioriIcon.actions.edit), state: .completed), - StepItemData(title: "Settings", node: .icon(FioriIcon.actions.actionSettings), state: .normal, substeps: [StepItemData(title: "Settings 1")]), - StepItemData(title: "Other0", state: .disabled), - StepItemData(title: "Other1", state: .completed), - StepItemData(title: "other2", state: .error)] @State var textSteps = [StepItemData(title: "Sign In", state: .completed), StepItemData(title: "User Info", node: .text("AB"), state: .completed), StepItemData(title: "Account Info", state: .completed), @@ -74,7 +67,6 @@ struct SPIExampleWithIcon: View { StepItemData(title: "Other1", state: .completed), StepItemData(title: "other2", state: .error)] @State var iconSelection: String = "" - @State var mixtureSelection: String = "" @State var textSelection: String = "" var body: some View { VStack(alignment: .leading) { @@ -103,15 +95,6 @@ struct SPIExampleWithIcon: View { self.updateCurrentStepName() } - Text("Step: Mixture Node").bold() - StepProgressIndicator(selection: self.$mixtureSelection, - stepItems: self.mixtureSteps) - { - Text("Invariant title").lineLimit(1) - } action: {} - .stepProgressIndicatorNodeType(.mixture) - .padding() - Text("Step: Only Text Node").bold() StepProgressIndicator(selection: self.$textSelection, stepItems: self.textSteps) diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift index dd3d14a39..814818abe 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift @@ -15,10 +15,8 @@ public protocol StepItem { var node: TextOrIcon? { get } } -/// Node of Step Progress Indicator display type, default is `mixture`. +/// Node of Step Progress Indicator display type, default is `text`. public enum StepProgressIndicatorNodeType { - /// Text and icon. - case mixture /// Only text. case text /// Only icon. diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift index deca31e49..63c5c49e7 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift @@ -23,7 +23,7 @@ extension EnvironmentValues { } struct StepProgressIndicatorNodeTypeKey: EnvironmentKey { - static let defaultValue: StepProgressIndicatorNodeType = .mixture + static let defaultValue: StepProgressIndicatorNodeType = .text } extension EnvironmentValues { diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index 8c9ba4a81..6906a702c 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -102,16 +102,6 @@ struct DefaultSingleStep: View { self.node(by: self.stepItem.state, isSelected: isSelected) self.noNodeStep() switch self.type { - case .mixture: - switch self.stepItem.node { - case .text(let string): - Text(string) - .font(Font.fiori(forTextStyle: .footnote)) - case .icon(let image): - image - case .none: - EmptyView() - } case .icon: switch self.stepItem.node { case .icon(let image): @@ -154,7 +144,7 @@ struct DefaultSingleStep: View { func noNodeStep() -> some View { if self.stepItem.node == nil { switch self.type { - case .mixture, .text: + case .text: Text("\(self.index + 1)") .font(Font.fiori(forTextStyle: .footnote)) case .icon: From 9a24b90d743984378d28360921f21a593ef70172 Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Tue, 10 Sep 2024 09:22:42 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Step=20Progress=20In?= =?UTF-8?q?dicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove stepProgressIndicatorNodeType implementation --- .../StepProgressIndicatorExample.swift | 8 ++---- .../StepProgressIndicator/StepItem.swift | 8 ------ .../StepsEnvironment.swift | 20 ------------- .../StepProgressIndicator/_DefaultSteps.swift | 28 ++++--------------- 4 files changed, 8 insertions(+), 56 deletions(-) diff --git a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift index 2fe46da1b..b803ff219 100644 --- a/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift +++ b/Apps/Examples/Examples/FioriSwiftUICore/StepProgressIndicator/StepProgressIndicatorExample.swift @@ -56,9 +56,9 @@ struct SPIExampleWithIcon: View { StepItemData(title: "User Info", node: .icon(FioriIcon.people.personPlaceholder), state: .completed), StepItemData(title: "Account Info", node: .icon(FioriIcon.actions.edit), state: .completed), StepItemData(title: "Settings", node: .icon(FioriIcon.actions.actionSettings), state: .normal, substeps: [StepItemData(title: "Settings 1")]), - StepItemData(title: "Other0", state: .disabled), - StepItemData(title: "Other1", state: .completed), - StepItemData(title: "other2", state: .error)] + StepItemData(title: "Other0", node: .icon(Image(systemName: "app.dashed")), state: .disabled), + StepItemData(title: "Other1", node: .icon(Image(systemName: "app.dashed")), state: .completed), + StepItemData(title: "other2", node: .icon(Image(systemName: "app.dashed")), state: .error)] @State var textSteps = [StepItemData(title: "Sign In", state: .completed), StepItemData(title: "User Info", node: .text("AB"), state: .completed), StepItemData(title: "Account Info", state: .completed), @@ -86,7 +86,6 @@ struct SPIExampleWithIcon: View { } } } - .stepProgressIndicatorNodeType(.icon) .padding() .onChange(of: self.iconSelection, perform: { _ in self.updateCurrentStepName() @@ -101,7 +100,6 @@ struct SPIExampleWithIcon: View { { Text("Invariant title").lineLimit(1) } action: {} - .stepProgressIndicatorNodeType(.text) .padding() Spacer().padding(20) diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift index 814818abe..43c879312 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepItem.swift @@ -14,11 +14,3 @@ public protocol StepItem { /// Step node. var node: TextOrIcon? { get } } - -/// Node of Step Progress Indicator display type, default is `text`. -public enum StepProgressIndicatorNodeType { - /// Only text. - case text - /// Only icon. - case icon -} diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift index 63c5c49e7..d7f7a8a1b 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/StepsEnvironment.swift @@ -22,26 +22,6 @@ extension EnvironmentValues { } } -struct StepProgressIndicatorNodeTypeKey: EnvironmentKey { - static let defaultValue: StepProgressIndicatorNodeType = .text -} - -extension EnvironmentValues { - var stepProgressIndicatorNodeType: StepProgressIndicatorNodeType { - get { self[StepProgressIndicatorNodeTypeKey.self] } - set { self[StepProgressIndicatorNodeTypeKey.self] = newValue } - } -} - -public extension View { - /// The style of the node of `StepProgressIndicator`. - /// - Parameter type: `StepProgressIndicatorNodeType` enum values. - /// - Returns: A new `StepProgressIndicator` with specific node. - func stepProgressIndicatorNodeType(_ type: StepProgressIndicatorNodeType) -> some View { - self.environment(\.stepProgressIndicatorNodeType, type) - } -} - public extension View { /// Step style for `StepProgressIndicator`. /// - Parameter style: Style for `StepProgressIndicator`. diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index 6906a702c..8620930df 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -53,7 +53,6 @@ struct DefaultSingleStep: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize @Environment(\.stepAxis) var stepAxis @Environment(\.stepFrames) var stepFrames - @Environment(\.stepProgressIndicatorNodeType) var type var stepItem: StepItem @Binding var selection: String @@ -100,23 +99,19 @@ struct DefaultSingleStep: View { } node: { ZStack { self.node(by: self.stepItem.state, isSelected: isSelected) - self.noNodeStep() - switch self.type { - case .icon: + if self.stepItem.node != nil { switch self.stepItem.node { case .icon(let image): image - case .none, .text: - EmptyView() - } - case .text: - switch self.stepItem.node { case .text(let string): Text(string) .font(Font.fiori(forTextStyle: .footnote)) - case .icon, .none: + case .none: EmptyView() } + } else { + Text("\(self.index + 1)") + .font(Font.fiori(forTextStyle: .footnote)) } } .frame(width: self.sideLength, height: self.sideLength) @@ -140,19 +135,6 @@ struct DefaultSingleStep: View { } } - @ViewBuilder - func noNodeStep() -> some View { - if self.stepItem.node == nil { - switch self.type { - case .text: - Text("\(self.index + 1)") - .font(Font.fiori(forTextStyle: .footnote)) - case .icon: - Image(systemName: "app.dashed") - } - } - } - @ViewBuilder func singleSubstep() -> some View { if self.stepItem.state.isSupported { From ffc38d611c3cdeca65797d1458c6facd618b4fe1 Mon Sep 17 00:00:00 2001 From: "Zuo, Kun" Date: Wed, 11 Sep 2024 10:46:19 +0800 Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Modify=20code=20?= =?UTF-8?q?using=20TextOrIconView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/StepProgressIndicator/_DefaultSteps.swift | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift index 8620930df..0c6ad439d 100644 --- a/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift +++ b/Sources/FioriSwiftUICore/Views/StepProgressIndicator/_DefaultSteps.swift @@ -99,20 +99,11 @@ struct DefaultSingleStep: View { } node: { ZStack { self.node(by: self.stepItem.state, isSelected: isSelected) - if self.stepItem.node != nil { - switch self.stepItem.node { - case .icon(let image): - image - case .text(let string): - Text(string) - .font(Font.fiori(forTextStyle: .footnote)) - case .none: - EmptyView() - } - } else { + if self.stepItem.node == nil { Text("\(self.index + 1)") .font(Font.fiori(forTextStyle: .footnote)) } + TextOrIconView(self.stepItem.node) } .frame(width: self.sideLength, height: self.sideLength) .overlay {