apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.36k stars 160 forks source link

ASCollectionView wrapped in NavigationView causing bottom cells on screen to reload after dismissing keyboard #190

Open skunkworker opened 4 years ago

skunkworker commented 4 years ago

Describe the bug When a ASCollectionView is wrapped inside of a NavigationView and you present a Sheet View with an editable field. If you are focused on the editable field and then dismiss the view, which dismisses the keyboard, the last few items are being "reloaded" with an animation from the left.

To Reproduce This small test app reproduces this bug. https://github.com/skunkworker/ascollection-view-bug-testapp Click the "+" at the top, then click "Close" or "Save"

Expected behaviour The sheet should be dismissed without any of the cell items refreshing.

Screenshots

The animation shows that the last cell loads in when it should be fully loaded at this stage of the keyboard dismissal.

Video included in bug reproduction repository above.

Screen Shot 2020-11-17 at 11 55 31 PM Screen Shot 2020-11-17 at 11 55 36 PM Screen Shot 2020-11-17 at 11 55 43 PM Screen Shot 2020-11-17 at 11 55 49 PM

Xcode Version:

Simulator, Device, Both?

skunkworker commented 4 years ago

This issue appears to be very odd. I am logging each of the cells with their number every time they appear and disappear. Sometimes the sheet can be presented without the cells disappearing, but the cells that disappear and reappear when the keyboard is brought up always show the issue.

Other times those same cells are never disappeared/appeared and the issue does not show up.

skunkworker commented 3 years ago

I got around this bug by changing the itemSize to absolute instead of estimated. I think this may be because the estimated size changes for the cells that are being blocked by the keyboard. It's hackish but it works.

                return ASCollectionLayoutSection
                {
                    let itemSize = NSCollectionLayoutSize(
                        widthDimension: .fractionalWidth(1.0),
                        heightDimension: .absolute(60))
                    let item = NSCollectionLayoutItem(layoutSize: itemSize)
apptekstudios commented 3 years ago

I think this might have to do with SwiftUI's new keyboard avoidance behaviour. I am curious if this still happens when using the v1.8.0 branch? Otherwise, it seems that the cells' frames are being set within an animation block, which is odd given this is managed by UICollectionView outside of our control.

skunkworker commented 3 years ago

@apptekstudios I just tested this on v1.8.0WIP and I'm still seeing the original behavior.