HeroTransitions / Hero

Elegant transition library for iOS & tvOS
https://HeroTransitions.github.io/Hero/
MIT License
22.06k stars 1.73k forks source link

Animation not working for UICollectionViewDiffableDataSource #745

Open EyalHouzz opened 2 years ago

EyalHouzz commented 2 years ago

What did you do?

I am trying to use Hero to animate transitions into a screen that is rendered with UICollectionView with UICollectionViewDiffableDataSource, by calling apply snapshot (NSDiffableDataSourceSnapshot)

What did you expect to happen?

To see the animation between the views that have matching hero ids

What happened instead?

The screen appears with the hero fade only On dismissing, the hero animations works perfectly (which removes the option that ids weren't defined properly, or any other setup issue)

From my investigation, if I add a delay of 2 seconds before presenting the screen, the animation works. I also checked and saw that the the cells still didn't render when Hero tried to animate

Also, in another screen, that works with the same lifecycle exactly but without the diffable datasource, the hero animation works! I also tried triggering apply snapshot without animations, or with the iOS 15 API (applySnapshotWithReloadData)

Is there a way to get this to work?

General Information

SubvertDev commented 1 year ago

I'm having similar issues, animating an image from a collectionView to an image in a collectionView on another screen that uses DiffableDataSource wasn't working until I've wrapped my pushViewController call into Task { @MainActor in ... } (or just DispatchQueue.main.asyncAfter(deadline: .now() + 0.01)), but it doesn't seem like a robust solution.

Also, this problem happens only on a real device, simulator works fine without these workarounds.