Hello everyone,
Everything was fine in IOS15, but now in IOS16 there is an issue with the opening of sheets attached to a View inside LazyVStack or LazyVGrid inside a ScrollView.
Here is some kind of simplified code, just to understand :
ScrollView {
LazyVStack { // or LazyVGrid, same problem
ForEach(products, id: \.self) { product in
MyViewThatHasASheetAttachedInside(product: product)
// The sheet inside is type : .sheet(item: fromNilToItem?)
// Inside this view, an .onTapGesture create the item, and that makes the sheet open
}
}
}
The view open fine for a randomly number of opening, but at some point, when you scroll, open, scroll, open, the sheet doesn't appear anymore. It's like it considers the sheet is already opened, but in fact not visible.
Weird facts :
- when it blocks, if you try to open an other sheet, it continues to block, but at some point all the sheets blocked can sometimes open suddenly one behind the other (alone, it open close, open close...), or crash.
- when it blocks, when you tap on an other type of view (like the tabbar), the sheet then appears as it should.
- when it blocks, sometimes, you scroll again, and you can open a sheet again.
When you change LazyVStack for a classic VStack, no more problem...
I found a sort of hack to avoid the problem, but this is not normal, and i'd like to know if someone already faced the same issue.
The hack consists in adding an "if something" inside the scrollView, and toggle it just before open the Sheet... (if it can help someone one day).