I'm using UICollectionView with NSDiffableDataSource and UICollectionViewFlowLayout, which looks like horizontal sequence of covers.
By default, the insert animation looks like all the cells right to the inserted cell are moved to the right after insertion, like this:
before:
center
|
[1] [2] [3] [4] [5]
after we've added X between 1 and 2:
center
|
[1] [X] [2] [3] [4]... (5 is offscreen)
But what i want to achive is that if we add an item to the left of the center, then collection expands to the left, and respectively if we add an item to the right then it expands to the right, leaving the middle where it was originally. Like this:
after we've added X between 1 and 2:
| center |
| | |
...|[X] [2] [3] [4] [5]| (1 is offscreen now)
after we've added X between 3 and 4:
| center |
| | |
|[1] [2] [3] [X] [4]|... (5 is offscreen)
I've tried using scrollTo / selectItem(at:animated:scrollPosition:) with scrollPosition = .centeredHorizontally and indexPath of item which was centered originally, both animated and not, but it looks bad, twitching because insertion and scroll animations overlap.