I've got several collection views that use diffable datasources, and we were generally very happy with how they worked until we noticed some strange behavior on iPad. We have a universal app that works on both iPhone and iPad and everything seems to be fine until you scroll to the bottom of a list on iPad. When you hit the home button there appears to be an attempt by the device to take a snapshot of the app, which is understandable, except that the frame changes when this happens and a redraw is requested by the collection view. Because the new view is narrower than the old one it makes it appear as if the list is longer than it is, and that we're now somewhere in the middle of it. When the app comes back to the foreground the correct frame is restored but the intermediary scroll offset is applied which gives a really janky feel because things don't appear to be how we left them. So to summarize:
We are using the new iOS 14 split view controller to host these views. It happens in both the primary and secondary containers.
Below is the call stack for what is modifying the view hierarchy when I hit the home button in the simulator:
If I put a simple print statement in my datasource I get different values based upon whether the app is in the foreground vs. just processing as it hits the background, which I think is the root problem.
We're in the foreground!
Size of the collection view: (703.5, 768.0)
☝️[OsuListCollectionViewController.swift]:236 26 configureDataSource()
Oh no we're in the background now!
Size of the collection view: (447.5, 1024.0)
☝️[OsuListCollectionViewController.swift]:236 26 configureDataSource()
Diffable collection view loads
Hit the home button
FBSSceneSnapshotAction runs
View frame is resized as it's minimizing for some reason, subviews are redrawn, data source configuration methods are re-run
App is brought to foreground again but the content offset is now incorrect, somewhere up in the middle of the list.
We are using the new iOS 14 split view controller to host these views. It happens in both the primary and secondary containers.
Below is the call stack for what is modifying the view hierarchy when I hit the home button in the simulator:
If I put a simple print statement in my datasource I get different values based upon whether the app is in the foreground vs. just processing as it hits the background, which I think is the root problem.
We're in the foreground!
Size of the collection view: (703.5, 768.0)
☝️[OsuListCollectionViewController.swift]:236 26 configureDataSource()
Oh no we're in the background now!
Size of the collection view: (447.5, 1024.0)
☝️[OsuListCollectionViewController.swift]:236 26 configureDataSource()