Implement a struct with single Rectangle with index parameter for each view to start and stop the animation programmatically via publisher with PassthroughSubject is passed as a parameter — which sends stream of values from their origin to it’ subscribers. The PassthroughSubject's subscribers can use this information to update the state of the UI or to handle the occurred event. In .onReceive will have access to the value sent by the publisher to act on to update the UI state.

@State Variable animate is set to true or false based on the value received from the publisher to control the opacity of the RectangleView

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

PassthroughSubject takes AnimationStatus enum to start, stop at particular index and completely everything.

References : https://gist.github.com/badrinathvm/13b79f1d6dfd30ea54a106dc1d805953

Happy Coding !!

Senior iOS Engineer @ Intuit | Exploring, Experimenting new ways of building mobile apps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store