onmyway133 / DeepDiff

🦀Amazingly incredible extraordinary lightning fast diffing in Swift
https://onmyway133.com/apps/
Other
2.05k stars 145 forks source link

Collectionview loosing scroll position #26

Closed ergunkocak closed 5 years ago

ergunkocak commented 5 years ago

Hi,

First of all thanks a lot for such useful library. I have a list interface which loads old items on scroll. My problem is after applying changes i am collectionView is loosing the current position after inserting new items above. To overcome i applied a technique i found in SO but it causes a flicker effect. Here what i used:

let contentHeight = collectionView!.contentSize.height
let offsetY = collectionView!.contentOffset.y
let bottomOffset = contentHeight - offsetY

let changes = diff(old: messages.old, new: messages.new)
collectionView!.reload(changes: changes, section: 0, completion: { _ in
    self.collectionView!.contentOffset = CGPoint(x: 0, y: self.collectionView!.contentSize.height - bottomOffset)
    })

Any suggestions?

Best

onmyway133 commented 5 years ago

@ergunkocak I haven't got this problem. Can you reproduce this in a demo project and send it here?

ergunkocak commented 5 years ago

Sorry for the late reply. I just saw your reply. I dont even remember what happened :( Sorry