Post

Replies

Boosts

Views

Activity

Reply to ForEach in Widget: How to fit only the number of items that can be fully visible?
I have been stuck on this exact problem for a while now, tried almost everything you can think of: hard code max values… but it's just silly because widget sizes varies PER device (large on iPhone SE is not the same as iPhone 15 Pro Max for example) etc… read the geometry and try to hide overflowing items… kind of worked, but brought in so many more problems I gave up… LazyVStack … same behavior of a VStack it will render overflowing content and you can see the last items clipped like your screenshot… the only thing that works is to use ViewThatFits like you said, but how did you do it? @nemecek_f In my case I have something like this, but I fear this may be memory intensive (or could be) and kill my widget, since it's very limited in memory in the widget process: `public var body: some View { ViewThatFits(in: .vertical) { ForEach(0..<maxSlots, id: .self) { cutOut in bodyThatFits(slots: maxSlots - cutOut) } } } func bodyThatFits(slots: Int) -> some View { // … the actual content of my widget // rendered with only up to the slots passed ` so in my case, it will try to render the widget with the max slots possible, or try and hide 1, or hide 2, etc… until it basically hides all of them… I have set max slots per widget family.
Oct ’23