diniska / modal-view

Present Modal view with Swift UI in the same way you would do with NavigationView
MIT License
92 stars 9 forks source link

Dismiss when parent view updates #15

Closed p-z-l closed 3 years ago

p-z-l commented 3 years ago

The modal will dismiss after the parent view updates, here's a piece of code that can re-create this bug:

import SwiftUI
import ModalView

struct ContentView: View {

    @State var demoText = "hello, world"

    var body: some View {
        Text(demoText)
        ModalPresenter {
            ModalLink(destination: TextField("", text: $demoText)) {
                Text("Show modal")
            }
        }
    }

}

Every time the user change the text in the modal sheet, the modal will dismiss unexpectedly. But this no longer happens after removing Text(demoText), so I guess that it dismissed because the parent view was updated.

diniska commented 3 years ago

Have you tried moving the ModalPresenter one level upper so that it is not affected by the state change? It is one of the reasons why we separate the ModalPresenter and the ModalLink.

p-z-l commented 3 years ago

It's working for me, thanks!