title: How to enable action with Lottie Button animation in SwiftUI?
body: <p>I have a simple project which is running a Lottie animation when tapping on a Button.</p>
  <pre><code>struct ContentView: View {
  
  @State var number = 0
  @State var toogleValue : Bool = false
  
  var body: some View {
      ZStack {
          Color.green.opacity(0.2)
          ZStack {
              LottieButton(filename: &quot;17247-happy-flower&quot;)
                 .frame(width: 200)
                 .onTapGesture {
                      self.number += 1
              }
              Text(&quot;number = \(self.number)&quot;)
              .offset( y: 150)
          }
      }.edgesIgnoringSafeArea(.all)
  }
  }
  </code></pre>
  <p>What I am trying to achieve is:  Whenever the user taps on the Button, the animation should start and the number counter should increase by 1.</p>
  <p>What is happening now: The counter is increasing by 1 but the animation is not playing.</p>
  <p>What I tried: When I comment // onTapGesture {self.number += 1} the animation is working fine, but then the counter is not working.</p>
  <p>Here is the Lottie Button:</p>
  <pre><code>  struct LottieButton: UIViewRepresentable {
  /// Create a button.
  let animationButton = AnimatedButton()
  var filename = &quot;LottieLogo2&quot;
  
  func makeUIView(context: UIViewRepresentableContext&lt;LottieButton&gt;) -&gt; UIView {
  let view = UIView()
  
  let animation = Animation.named(filename)
  animationButton.animation = animation
  animationButton.contentMode = .scaleAspectFit
  
  animationButton.translatesAutoresizingMaskIntoConstraints = false
  view.addSubview(animationButton)
  
  animationButton.clipsToBounds = false
     /// Set animation play ranges for touch states
  animationButton.setPlayRange(fromMarker: &quot;touchDownStart&quot;, toMarker: &quot;touchDownEnd&quot;, event: .touchUpInside)
   //  animationButton.setPlayRange(fromMarker: &quot;touchDownEnd&quot;, toMarker: &quot;touchUpCancel&quot;, event: .touchUpOutside)
   //  animationButton.setPlayRange(fromMarker: &quot;touchDownEnd&quot;, toMarker: &quot;touchUpEnd&quot;, event: .touchUpInside)
                                   
  NSLayoutConstraint.activate([
      animationButton.heightAnchor.constraint(equalTo: view.heightAnchor),
      animationButton.widthAnchor.constraint(equalTo: view.widthAnchor),
  ])
  
  return view
  }
  
  func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext&lt;LottieButton&gt;) {
           
  }
  }
  </code></pre>
  <p>I assume the problem is due to the hierarchy of the View, but I am not sure.</p>
  <p><a href="https://i.stack.imgur.com/SkiR2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SkiR2.png" alt="Screenshot from the app" /></a></p>