See this actually expectations: Here when check box false show index 1,2 and FormStep2, FormStep3
Here see this example when check box true show index 1,2,3 and FormStep1, FormStep2, FormStep3
Here adjusted index baed on true and false.
Where as my logic example of iOS app image is: Here see this index and FormStep label compare to above image
Here check the index and Formstep after checkBox true
I am unable to adjust index based on flag. please any one help to me for this logic find blow my code
Here this is getting list from json
struct StepperView: View {
let stepperViewModel: StepperViewModel
var body: some View {
ScrollView {
VStack(spacing: 5) {
ForEach(Array(stepperViewModel.children.enumerated()), id:\.element.id) { index, step in
StepView(
stepCount: index,
step)
}
}
.padding(.vertical, 6)
}
}
}
then create a step view and pass the index also
struct StepView: View {
private var stepCount: Int
private let step: StepViewModel
@ObservedObject var displayRule: AnyValue
init(stepCount: Int, _ step: StepViewModel) {
self.step = step
displayRule = step.displayRule ?? AnyValue(value: true)
self.stepCount = step.displayRule?.value == true ? stepCount : 0
}
@ViewBuilder
var drawStepView: some View {
HStack (alignment: .top, spacing: 15) {
VStack(spacing: 5) {
ZStack {
Circle()
.frame(width: 30, height: 30)
.foregroundColor(.gray)
Text("\(stepCount + 1)")
.font(.body)
.foregroundColor(.white)
.frame(alignment: .center)
}
}
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 6)
}
@ViewBuilder
var body: some View {
if displayRule.value {
drawStepView
}
}
}
Here I draw the view based on if displayRule.value {
drawStepView
} condition and then when I check box make true or false based on @ObservedObject var displayRule: AnyValue ObservedObject updated draw view.
Anyvalue code is
class AnyValue: ObservableObject {
let valueObserver = PassthroughSubject<Void, Never>()
@Published var value: Bool {
didSet {
valueObserver.send()
}
}
init(value: Bool) {
self.value = value
}
}
I provide code please identify the issue provide index adjustment solution here.