Guest User

Untitled

a guest
Dec 14th, 2025
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.24 KB | Source Code | 0 0
  1. struct ContentView: View {
  2.    
  3.     @State private var workoutRegoFlowShowing: Bool = false
  4.    
  5.     var body: some View {
  6.         Button("Add New Workout") {
  7.             workoutRegoFlowShowing.toggle()
  8.         }
  9.         .sheet(isPresented: $workoutRegoFlowShowing) {
  10.             WorkoutRegoFlow()
  11.         }
  12.     }
  13. }
  14.  
  15. struct WorkoutRegoFlow: View {
  16.     @Environment(\.dismiss) private var dismiss
  17.    
  18.     @State private var step: Int = 0
  19.    
  20.     var body: some View {
  21.         VStack {
  22.             // Top bar
  23.             HStack {
  24.                 Button {
  25.                     goBack()
  26.                 } label: {
  27.                     Image(systemName: "arrow.left")
  28.                         .font(.title2)
  29.                         .fontWeight(.semibold)
  30.                         .foregroundStyle(.black)
  31.                         .rotationEffect(Angle(degrees: step == 0 ? 270 : 360))
  32.                 }
  33.                 Spacer()
  34.             }
  35.             .padding()
  36.            
  37.             TabView(selection: $step) {
  38.                 Step1View(step: $step)
  39.                     .tag(0)
  40.                
  41.                 if step >= 1 {
  42.                     Step2View(step: $step)
  43.                         .tag(1)
  44.                 }
  45.                 if step >= 2 {
  46.                     Step3View(step: $step)
  47.                         .tag(2)
  48.                 }
  49.             }
  50.             .tabViewStyle(.page)
  51.         }
  52.     }
  53.    
  54.     private func goBack() {
  55.         if step == 0 {
  56.             dismiss()
  57.         } else {
  58.             withAnimation { step -= 1 }
  59.         }
  60.     }
  61. }
  62.  
  63. struct Step1View: View {
  64.     @Binding var step: Int
  65.    
  66.     var body: some View {
  67.         VStack {
  68.             Text("Step 1")
  69.             Button("Next") { withAnimation { step += 1 } }
  70.         }
  71.     }
  72. }
  73.  
  74. struct Step2View: View {
  75.     @Binding var step: Int
  76.    
  77.     var body: some View {
  78.         VStack {
  79.             Text("Step 2")
  80.             Button("Next") { withAnimation { step += 1 } }
  81.         }
  82.     }
  83. }
  84.  
  85. struct Step3View: View {
  86.     @Binding var step: Int
  87.    
  88.     var body: some View {
  89.         VStack {
  90.             Text("Step 3")
  91.             Button("Finish") { print("Done") }
  92.         }
  93.     }
  94. }
  95.  
  96. #Preview {
  97.     ContentView()
  98. }
Tags: Swiftui
Advertisement
Add Comment
Please, Sign In to add comment