GeometryReader problem

I'm adding Admob ads to my app, and Admob needs to know the width of the view, so I'm using GeometryReader for that. To prevent GeometryReader from grabbing screen space, I've wrapped the main view in GeometryReader { }. I then use geometry.size.width in my call to the adView.

This all works fine. I have two main screens where I show ads, and they both work, until I rotate the device. Then the app crashes!

If I comment out the GeometryReader code and pass a fixed value to the ad view, I can rotate the device with no fear of a crash.

My question is: Do I have to accept that GeometryReader will crash the app when it's rotated, or is there another, stable way to get view dimensions?

Without seeing your code we can only speculate:

It could be possible that the size is reported as beeing zero for a short period. Change your code to prevent using a size of zero and see if that solves the problem.

The error I'm getting:

Thread 1: Fatal error: <UpdateCoalescingCollectionView 0x3037efc30> is stuck in a recursive layout loop. This can happen when self-sizing views do not return consistent sizes, or the collection view's frame/bounds/contentOffset is being constantly adjusted. To debug this issue, check the Console app for logs in the "UICollectionViewFeedbackLoopDebugger" category. Collection view: <SwiftUI.UpdateCoalescingCollectionView: 0x156f96a00; baseClass = UICollectionView; frame = (0 0; 852 149); clipsToBounds = YES; autoresiz

It turns out that the problem isn't with GeometryReader, it's with LazyVGrid.

I'm not clear on why, but my grid with 5 columns doesn't always report the same size. I can make it work by adding a 6th column that doesn't get used in the view. Very odd.

GeometryReader problem
 
 
Q