How to handle multiple layer of modal in SwiftUI ?

Hi,

I want to be able to have multiple layer of modal in SwiftUI like what you can do in UIKit.

When you run the code below(in playground) it will create layer upon layer of modal.

Code Block swift
import UIKit
import PlaygroundSupport
extension UIColor {
class func randomColor(randomAlpha: Bool = false) -> UIColor {
let redValue = CGFloat(arc4random_uniform(255)) / 255.0;
let greenValue = CGFloat(arc4random_uniform(255)) / 255.0;
let blueValue = CGFloat(arc4random_uniform(255)) / 255.0;
let alphaValue = randomAlpha ? CGFloat(arc4random_uniform(255)) / 255.0 : 1;
return UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: alphaValue)
}
}
class ModalViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.randomColor()
let button = UIButton()
button.backgroundColor = .clear
button.setTitle("Open", for: .normal)
button.setTitleColor(self.view.tintColor, for: .normal)
button.addTarget(self, action: #selector(presentModal(_:)), for: .touchUpInside)
button.sizeToFit()
button.center = self.view.center
self.view.addSubview(button)
}
@IBAction func presentModal(_ sender: UIButton) {
let presentee = ModalViewController(nibName: nil, bundle: nil)
self.modalPresentationStyle = .overCurrentContext
self.modalTransitionStyle = .flipHorizontal
self.modalPresentationCapturesStatusBarAppearance = true
self.present(presentee, animated: true, completion: nil)
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton()
button.backgroundColor = .clear
button.setTitle("Open", for: .normal)
button.setTitleColor(self.view.tintColor, for: .normal)
button.addTarget(self, action: #selector(presentModal(_:)), for: .touchUpInside)
button.sizeToFit()
button.center = self.view.center
self.view.addSubview(button)
}
@IBAction func presentModal(_ sender: UIButton) {
let presentee = ModalViewController(nibName: nil, bundle: nil)
self.modalPresentationStyle = .overCurrentContext
self.modalTransitionStyle = .flipHorizontal
self.modalPresentationCapturesStatusBarAppearance = true
self.present(presentee, animated: true, completion: nil)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = ViewController()


I did tried various approach in SwiftUI but I didn't seems to find how to do it is anyone have an idea ?

Thanks,
How to handle multiple layer of modal in SwiftUI ?
 
 
Q