Created
October 4, 2022 12:06
-
-
Save SarahAlsharif/dd86766e352dfc3e90bcdffa02d085dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MultiStepsView <T, Content: View> : View where T: Swift.CaseIterable { | |
@Binding var steps: [T] | |
let extraContent : [String]? | |
let extraContentPosition : ExtraContentPosition? | |
let extraContentSize : CGSize? | |
let action : (Int) -> Void | |
@ViewBuilder let content: () -> Content | |
@State var numberOfSteps : Int = 0 | |
@State var widthOfLastItem = 0.0 | |
@State var images : [UIImage] = [] | |
@ViewBuilder | |
var body: some View { | |
VStack { | |
HStack { | |
ForEach(0..<numberOfSteps, id: \.self) { index in | |
ZStack { | |
HStack(spacing: 0) { | |
VStack { | |
if let extraContent = extraContent, extraContentPosition == .above { | |
ExtraStepContent(index: index, color: index < steps.count ? .accentColor :.gray, extraContent: extraContent, extraContentSize: extraContentSize) | |
} | |
content().foregroundColor(index < steps.count ? .accentColor :.gray) | |
} | |
if let extraContent = extraContent, extraContentPosition == .inline { | |
ExtraStepContent(index: index, color: index < steps.count ? .accentColor :.gray, extraContent: extraContent, extraContentSize: extraContentSize) | |
} | |
} | |
}.overlay { | |
if let extraContent = extraContent, extraContentPosition == .onTop , index < steps.count { | |
ExtraStepContent(index: index, color: .accentColor, extraContent: extraContent, extraContentSize: extraContentSize) | |
} | |
} | |
.onTapGesture { | |
action(index) | |
} | |
} | |
} | |
}.onAppear() { | |
numberOfSteps = type(of: steps).Element.self.allCases.count | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment