GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Sheet on LazyVStack or LazyVGrid inside a ScrollView doesn't open randomly (IOS16)

Forums > SwiftUI

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).

2      

Hi everybody, All was great in IOS15, however presently in IOS16 there is an issue with the launch of sheets connected to a View inside LazyVStack or LazyVGrid inside a ScrollView. https://gosloto.co/

2      

I improve my English thanks to you, cool. Besides that ?

2      

Hacking with Swift is sponsored by Alex.

SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!

Try for free!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.