Collection-View-in-a-Table-View-Cell
Collection-View-in-a-Table-View-Cell copied to clipboard
Falling back to 0 when setting content offset doesn't work when there's contentInset
Minor correction. If your collection view has contentInsets for example of UIEdgeInsets(top: 0, left: 24, bottom: 0, right: 24), the contentOffset.x will be -24 initially, so if you fall back to 0 when there's no stored offset that causes it to scroll over inappropriately.
Currently:
tableViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0
This is the fix (but requires the collectionView not be private):
tableViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? -tableViewCell.collectionView.contentInset.left