HeroTransitions / Hero

Elegant transition library for iOS & tvOS

Home Page:https://HeroTransitions.github.io/Hero/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Animation not working for UICollectionViewDiffableDataSource

EyalHouzz opened this issue · comments

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

  • Hero Version:
    latest

  • iOS Version(s):
    15.6.1

  • Swift Version:
    5

  • Devices/Simulators:
    iPhone 13 (real device)

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.