[iOS 16] App freeze when hitting back on navigation bar, using a WrappingHastack in a view as a NavigationLink
sadaf-behbahani opened this issue · comments
Describe the bug
On iOS 16, app meets a severe hang when using a wrappingHastack inside of a navigation link if you hit back button on the navigation bar.
To Reproduce
Steps to reproduce the behavior:
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink("Hit me ") {
WrappingView()
}
}
}
}
}
import WrappingHStack
struct WrappingView: View {
@State private var array: [String] = []
var body: some View {
VStack {
WrappingHStack(array,
id: \.self,
alignment: .center,
spacing: .constant(10)) { topic in
Text(topic)
}
}
.onAppear {
array = ["test",
"test3",
"test4",
"test5",
"test6",
"test7"]
}
}
}
- run the app with code above,
- hit the navigation link
- hit back button on the navigation bar
Expected behavior
Go back the previous screen and not freeze the app
Screenshots
If applicable, add screenshots to help explain your problem.
Context:
- WrappingHStack version: [e.g. 2.2.1]
- Model: iPhone 13 pro, simulator , iPhone 11
- OS: iOS 16
Additional context
Freeze happens only if you use this lib inside of a Navigation link
It seems to be related to an issue when using NavigationLink
with contained GeometryReaders that are not inside a NavigationView
. The workaround is to set a NavigationView
around the WrappingHStack
.
In your example, you could use:
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink("Hit me ") {
WrappingView()
}
}
}
}
}
import WrappingHStack
struct WrappingView: View {
@State private var array: [String] = []
var body: some View {
NavigationView { // <<<< HERE
VStack {
WrappingHStack(array,
id: \.self,
alignment: .center,
spacing: .constant(10)) { topic in
Text(topic)
}
}
.onAppear {
array = ["test",
"test3",
"test4",
"test5",
"test6",
"test7"]
}
}
}
}
For more information see this link
I have added this use case to the example app
Thank you 🙏
@dkk I have a similar problem in two cases but a more complicated structure. The workaround doesn't help.
Case 1
TabView {
NavigationView {
ScrollView {
WrappingHStack {
Case 2
TabView {
NavigationView {
ScrollView {
NavigationLink {
ScrollView {
WrappingHStack {
There are also intermediate views and ZStacks and VStacks that I didn't mention.