Replies: 1 comment 1 reply
-
Hi @olehpidhi, this is unfortunately just another bug in SwiftUI navigation and is reproducible in vanilla SwiftUI navigation. First, note that although you seem to have found a work around with your ad-hoc //With setter doing nothing navigation works as expected
.navigationDestination(isPresented: Binding<Bool>(get: {
viewModel.destination == .destination3
}, set: { isPresented in
print(isPresented)
}), destination: {
Rectangle().foregroundColor(.cyan)
})
.navigationDestination(isPresented: Binding<Bool>(get: {
viewModel.destination == .destinationLoading
}, set: { isPresented in
print(isPresented)
}), destination: {
Rectangle().foregroundColor(.brown)
}) …this only causes other problems. You must implement the If you update the .navigationDestination(isPresented: Binding<Bool>(get: {
viewModel.destination == .destination3
}, set: { isPresented in
viewModel.destination = isPresented ? .destination3 : nil // ⬅️
}), destination: {
Rectangle().foregroundColor(.cyan)
})
.navigationDestination(isPresented: Binding<Bool>(get: {
viewModel.destination == .destinationLoading
}, set: { isPresented in
viewModel.destination = isPresented ? .destinationLoading : nil // ⬅️
}), destination: {
Rectangle().foregroundColor(.brown)
}) …then you will see the exact same problem that you see with our The unfortunate reality is that .navigationDestination(unwrapping: $viewModel.destination, case: /ViewModel2.Destination.destinationLoading) { $model in
…
}
.navigationDestination(unwrapping: $viewModel.destination, case: /ViewModel2.Destination.destination3) { $model in
…
} Don't ask me why, I have no idea. 😅 Since this is not an issue with the library I am going to convert it to a discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
We have a screen that can trigger a long-running operation, and this navigates the user to a loading screen. After the operation is finished, automatic navigation to the result screen is triggered.
Checklist
main
branch of this package.Expected behavior
After the operation is finished, the user is navigated to a result screen.
Actual behavior
The behavior is unstable, sometimes I get navigated to the result screen successfully, and sometimes I get popped back to the screen that triggers the operation.
Steps to reproduce
Here's a sample project. It uses both vanilla SwiftUI
.navigationDestination
and.navigationDestination
from SwiftUI-Navigation. Changing.navigationDestination
to.fullscreenCover
for loading screen makes behavior even more weird when even operation triggering screen can be poped from navigation stack.NavigationTest.zip
SwiftUI Navigation version information
1.0.0
Destination operating system
16.4
Xcode version information
Version 14.3.1 (14E300c)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions