Implement a struct with single Rectangle with index parameter for each view to start and stop the animation programmatically via publisher with
PassthroughSubjectis passed as a parameter — which sends stream of values from their origin to it’ subscribers. The
PassthroughSubject'ssubscribers can use this information to update the state of the UI or to handle the occurred event. In
.onReceivewill have access to the value sent by the publisher to act on to update the UI state.
animate is set to true or false based on the value received from the publisher to control the opacity of the
Next, create ProgressView( see the references link below) with
@state currentIndex,publisher variables. In it’s
.onAppear pass the value via publisher to the it’s subscriber
RectangleView in this case
AnimationStatus enum to start, stop at particular index and completely everything.
Happy Coding !!