Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ContentView: View {
- @State private var workoutRegoFlowShowing: Bool = false
- var body: some View {
- Button("Add New Workout") {
- workoutRegoFlowShowing.toggle()
- }
- .sheet(isPresented: $workoutRegoFlowShowing) {
- WorkoutRegoFlow()
- }
- }
- }
- struct WorkoutRegoFlow: View {
- @Environment(\.dismiss) private var dismiss
- @State private var step: Int = 0
- var body: some View {
- VStack {
- // Top bar
- HStack {
- Button {
- goBack()
- } label: {
- Image(systemName: "arrow.left")
- .font(.title2)
- .fontWeight(.semibold)
- .foregroundStyle(.black)
- .rotationEffect(Angle(degrees: step == 0 ? 270 : 360))
- }
- Spacer()
- }
- .padding()
- TabView(selection: $step) {
- Step1View(step: $step)
- .tag(0)
- if step >= 1 {
- Step2View(step: $step)
- .tag(1)
- }
- if step >= 2 {
- Step3View(step: $step)
- .tag(2)
- }
- }
- .tabViewStyle(.page)
- }
- }
- private func goBack() {
- if step == 0 {
- dismiss()
- } else {
- withAnimation { step -= 1 }
- }
- }
- }
- struct Step1View: View {
- @Binding var step: Int
- var body: some View {
- VStack {
- Text("Step 1")
- Button("Next") { withAnimation { step += 1 } }
- }
- }
- }
- struct Step2View: View {
- @Binding var step: Int
- var body: some View {
- VStack {
- Text("Step 2")
- Button("Next") { withAnimation { step += 1 } }
- }
- }
- }
- struct Step3View: View {
- @Binding var step: Int
- var body: some View {
- VStack {
- Text("Step 3")
- Button("Finish") { print("Done") }
- }
- }
- }
- #Preview {
- ContentView()
- }
Advertisement
Add Comment
Please, Sign In to add comment