Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep contentOffset when data has been changed #80

Open
intoxicated opened this issue Nov 29, 2017 · 16 comments
Open

Keep contentOffset when data has been changed #80

intoxicated opened this issue Nov 29, 2017 · 16 comments

Comments

@intoxicated
Copy link

I've researched a lot regards to fix contentOffset after table dataSource has been updated. I couldn't find a way to do it with Dwifft. When diffCalculator.row = self.data is invoked with new values (in my case, new values will be added at front of previous data), it changes contentOffset. I attempted to use tableView.setContentOffset(offset, animated: false) after providing new data to diffCalculator which didn't work. Also, when new values (in this case, append to previous data) are added while scrolling, scroll somehow jumps on and off at some weird position. I also noticed, when same values were set to diffCalculator, it treated there were diff. I'd appreciate any advices. Thanks

@jflinter
Copy link
Owner

jflinter commented Dec 12, 2017 via email

@larryonoff
Copy link
Contributor

Just tried performBatchUpdates branch and it didn't help.

@larryonoff
Copy link
Contributor

I think that Dwifft should have method func setSectionedValues(_ values: ..., animated: Bool). This will help people using the library in case of having the same issue. I'm having the same issue, but I want using the library. I can create PR with the proposed functionality.

@larryonoff
Copy link
Contributor

I also think that performBatchUpdates is reasonable to merge into master. It just uses new iOS 11 functionality.

@jflinter
Copy link
Owner

jflinter commented Dec 19, 2017 via email

@larryonoff
Copy link
Contributor

larryonoff commented Dec 19, 2017 via email

@larryonoff
Copy link
Contributor

@intoxicated it looks that solutions is easy, but hacky. Try doing the following after settings sectionedValues tableView.layer.removeAllAnimations()

@jflinter
Copy link
Owner

@larryonoff - upon further consideration, I don't think your suggestion belongs in Dwifft - it's not, and should not be, responsible for how animations to collection views take place - that's what UICollectionViewLayout, etc is for. As a really simple example, you can get un-animated behavior today by doing something like

UIView.performWithoutAnimation {
  diffCalculator.sectionedValues = ...
}

What this thread needs a cogent explanation of how to preserve a table view's contentOffset without any visual artifacts when inserting rows/sections of variable height. I'm not really interested in pursuing any solutions until that is properly understood.

@intoxicated
Copy link
Author

intoxicated commented Dec 26, 2017

larryonoff's solution doesn't work for me, and moreover, it seems like I lose scroll contentOffset position unexpectedly when updating data while tableview has scrolled.. I'm investigating more on this topic atm tho

@danya61
Copy link

danya61 commented Nov 6, 2019

larryonoff's solution doesn't work for me, and moreover, it seems like I lose scroll contentOffset position unexpectedly when updating data while tableview has scrolled.. I'm investigating more on this topic atm tho

Did you find any solution?

@danya61
Copy link

danya61 commented Nov 6, 2019

One of the possible solution - perform update in [.default] runloop mode
RunLoop.current.perform(inModes: [.default]) { /* Perform update */ }
But in this approach your batchUpdates will be async. In my unusual case its not the best solution

@larryonoff
Copy link
Contributor

@danya61 I don't use Dwifft anymore. I switched to DifferenceKit

@danya61
Copy link

danya61 commented Nov 6, 2019

@danya61 I don't use Dwifft anymore. I switched to DifferenceKit

Well, I suppose that the issue doesn't associated with the especial library, I've reproduce it even without diff framework . I've got an error when if your content offset < 0 and RunLoop mode is tracking, then after insert section (at least) content offset becomes forced zero

@larryonoff
Copy link
Contributor

@danya61 hmmmm. I don't remember that I've faced with the current issue. But this not 100%

@Dreagvor
Copy link

I had the same issue, and resolved with setting collectionView.contentInsetAdjustmentBehavior = .never

@aimalygin
Copy link

For UICollectionView you might use StableCollectionViewLayout.
This issue is normal behaviour for UITableView/UICollectionView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants