title: Trying to create a swipe to confirm button in Swift Ui
body: <p>So, I saw many swipe to buy buttons around the web and on many apps. I thought it would be good to implement onto my app. But for some reason, the ZStack isn't functioning properly, the background is on top of the swipe arrow. I can't properly place it inside of another view. Furthermore, how would one perform an action when the swipable arrow is fully at the end?</p>
  <pre><code> 
  
  import SwiftUI
  
  struct ContentView: View {
      @State var viewState = CGSize(width: 0, height: 50)
  
      var body: some View {
       
          
          ZStack{
              
  /// This part is the background of the swipe to buy 
  
              RoundedRectangle(cornerRadius: 10)
                  .offset(x: viewState.width)
                  .frame(width: 800,height: 100)
              
              HStack{
                  
  // This part is the actual swiping arrow 
  
                  ZStack {
                      RoundedRectangle(cornerRadius: 30)
                          .fill(Color.blue)
                          .frame(width: 100, height: 100)
                          .offset(x: viewState.width)
                          .gesture(
                              DragGesture().onChanged { value in
                                  viewState = value.translation
                              }
                              .onEnded { value in
                                  withAnimation(.spring()) {
                                      viewState = .zero
                                  }
                              }
                      )
                      
                      Image(systemName: &quot;chevron.right&quot;)
                          .offset(x: viewState.width)
                          .gesture(
                              DragGesture().onChanged { value in
                                  viewState = value.translation
                              }
                              .onEnded { value in
                                  withAnimation(.spring()) {
                                      viewState = .zero
                                  }
                              }
                      )
  
                  }
                  
                  
                  
                  Spacer()
              }
              
          }
              
              
    
              
          
         
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  '''
  </code></pre>