-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dismissed on EnvironmentObject change #8
Comments
@Erhannis Thanks for your question. Could you please provide an example of your view structure? I'm pretty sure that this can be solved by moving |
I may be able to make a demo view later, but the actual view in question is company code, so I unfortunately cannot provide the code. In any case, I believe that while testing, I'd placed the ModalPresenter at the top level, or nearly. It was above the modal ModalLink, at least. I suspect the problem is related to the following in the source comments for "sheet(item:onDismiss:content:)" : "item: a |
Here's a minimal example demonstrating the problem:
In SceneDelegate.swift, also change
to
I think that's all that's required. When you tap Button, the modal should appear correctly, but disappears in 4 seconds or less, when the EnvironmentObject is updated. The bug occurred on both a physical device and a simulator. |
@Erhannis thanks for the example. I'm able to reproduce it and going to fix the issue. Until then, you can use the next refactoring as a temporary solution: Leave struct ContentView: View {
var body: some View {
ModalPresenter {
EnvironmentContentView()
}
}
}
private struct EnvironmentContentView: View {
@EnvironmentObject var eo: EnvObj
var body: some View {
ModalLink(destination: Text("Modal")) {
Text("Button")
}
}
} This change leaves |
Thanks! I'll try that next time it comes up.
…On Mon, Jan 20, 2020 at 11:50 PM Denis ***@***.***> wrote:
@Erhannis <https://github.com/Erhannis> thanks for the example. I'm able
to reproduce it and going to fix the issue. Until then, you can use the
next refactoring as a temporary solution: Leave ModalPresenter inside the
ContentView and move the rest into a temporary view.
struct ContentView: View {
var body: some View {
ModalPresenter {
EnvironmentContentView()
}
}
}
private struct EnvironmentContentView: View {
@EnvironmentObject var eo: EnvObj
var body: some View {
ModalLink(destination: Text("Modal")) {
Text("Button")
}
}
}
This change leaves ContentView unaffected by changes and thus doesn't
dismiss the modal. It also shouldn't have a measurable effect on
performance as SwiftUI Views are very cheap.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8?email_source=notifications&email_token=AAXCNTPNOV2BWJOYXLQZDCDQ6Z5IFA5CNFSM4KBTBA3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJOPFTQ#issuecomment-576516814>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXCNTPJQAV4CRJHNE7EVDTQ6Z5IFANCNFSM4KBTBA3A>
.
|
@diniska Were you able to fix this? |
Hello, @bark1n9! My current suggestion is to separate the |
@diniska Thank you! I somehow missed that comment :) |
This library is much more convenient than the default way of doing modals, BUT, we have a view that gets automatically updated once a second or so. (It's tied to an EnvironmentObject.) When this happens, the modal disappears. Ideally, I'd like it to stay visible, and preferably be updated according to the changes which have occurred in the EnvironmentVariable, while the view under the modal is updated in the background. Can this be done?
The text was updated successfully, but these errors were encountered: