Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.84k stars 1.54k forks source link

[IGListDiff] How to get actual steps #1006

Open zdnk opened 6 years ago

zdnk commented 6 years ago

Hello, I would like to use diffing algorithm from IGListKit for my project and I am missing an information how to use it to get actual steps to get from original array to new one. There are moves, updates, deletes and inserts, but how do I apply them, what order. I would really appreciate this information as it is vital for what I need to do with it.

weyert commented 6 years ago

Have a look at the example macOS where we are using the ListAdapter to drive a NSCollectionView, see: https://github.com/Instagram/IGListKit/blob/d6e26d54e85a5c745a38a2693e34ae9fbbc0d639/Examples/Examples-macOS/IGListKitExamples/ViewControllers/UsersViewController.swift#L57-L87

zdnk commented 6 years ago

What should this tell me? I dont understand. My use case is I have two arrays. I will call ListDiff and then I need to use it somehow to get from array A to array B by applying insertions, deletions and moves on it.

weyert commented 6 years ago

Can you tell me what you exactly want to do? I understand you have array A and B and you use ListDiff to determine the changes, all the inserts, movements, deleted etc. This data is used the above example to animate the differences in NSCollectionView through performBatchUpdates

zdnk commented 6 years ago

I just need to know what actions/steps to perform to get from that array A to B ... Meaning how to apply those insertions, deletions etc. In what order lets say.

weyert commented 6 years ago

Delete, Insert, Move,

See also the file below as used in flushCollectionView in IGListAdapterUpdater https://github.com/Instagram/IGListKit/blob/master/Source/Internal/UICollectionView%2BIGListBatchUpdateData.m

rnystrom commented 6 years ago

@zdenektopic I'm a little confused why if you already have array B why you need to replay those steps. Can you described a little more what you're trying to achieve?

Replaying the mutations will be tricky as deletes and inserts will mutate the array as you're editing them. But something like:

zdnk commented 6 years ago

I am trying to modify view hierarchy. I have view with subviews, some of those subviews have also subviews. And I want to do diff of two hierarchies and apply the diff on the old one so it is turned into new one. Also apply animations on those being removed/inserted.

rnystrom commented 6 years ago

You should be able to use the above steps to perform the operations. You'll also need some sort of in-order "pool" of new stuff to pull from for inserts.

Are you diffing like a virtual view hierarchy or something? Where do the new views come from?

zdnk commented 6 years ago

Yep, it should be virtual view hierarchy. The current one vs the new one. Working on a little framework, something similar to React. Also using Yoga for layout.

rnystrom commented 6 years ago

Super cool. Let me know where you end up!

Sent with GitHawk