UICollectionViewDelegateFlowLayout methods not called on rotation in some devices

Hi All,


Initially I used to calculate width and reload my collection view to handle rotation. Recently I was going through Apple's WWDC video https://developer.apple.com/videos/play/wwdc2018/225/?time=733. According to this, flow layouts should handle calculation of width and everytime the collection view bounds will change the flow layout will be invalidated. This worked perfectly for the new iPhone Xr, on rotation the flow layout gets invalidated and the delegate function "sizeForItemAt" is called again. I'm overriding this function to give the cells the new width. Using this, I was able to improve to improve my app performance and fix a lot of layout issues I faced earlier.

However, this is not the case when I try to run the the same code in iPhone 6s or any other older device (running the same latest iOS). For older devices, the delegate function "sizeForItemAt" is not called on rotation. Hence, the cell width is not updated accordingly. I tried overriding "shouldInvalidateLayout" to always return true but that also didn't help. The only solution is to explicitly call "invalidateLayout" for my collection view in "viewWillTransition".

Why is the behaviour different for different devices even though they are on the same iOS version?

If user moves from Screen A to Screen B, rotates the device on Screen B and then comes back to Screen A, the cells in Screen A did not update the width since the device was rotated on another screen. How to handle this scenario? Should I invalidate the layouts in "viewWillAppear" for every view controller?


Regards,

Sanchit