How to call a function on original view when modal view is dismissed

I have a SwiftUI puzzle game. I store played puzzles and show in the history view. History view is displayed as a sheet when a button is tapped. In the history view, I want to have a button ("Replay puzzle") which should 1) dismiss the history view, and 2) run a function in the main view so that a game from history view can be replayed.

Seems simple but I could not figure out how to call a function in the main view to update the current game. Any pointers would be appreciated.

>Solution :

Use onDismiss parameter of .sheet, like in https://stackoverflow.com/a/63673342/12299030

Leave a Reply