Code Monkey home page Code Monkey logo

hdlistviewdiffer's Introduction

HDListViewDiffer

前言

目前开源的列表diff大多数为swift的,OC版本的很少。IGList通过Objective-C++实现了diff。HDListViewDiffer参考了其**,简化了diff函数。实现了一个轻量的,简化版本的纯OC diff库。

1、什么是 ListViewDiff ?

简单来说,就是查找一个滑动列表(这里指UITableView和UICollectionView)在更新数据后与更新数据之前的变化,如同git/svn提交新版本时通过diff来查看改变了哪些数据

2、为什么要做ListViewDiff ?

1、平时我们想动画 删除/移动/新增 某个cell时,往往需要自己计算变更前后的数据,进而得出相关的indexPath,最终拼凑 deleteRowsAtIndexPaths,insertRowsAtIndexPaths等方法实现。这里的问题在于一旦计算错误将会崩溃。且每次均需要自己计算并维护。通过HDListViewDiffer来变更数据则基本不必担心以上问题,你仅仅需要告知变化前后的数据源即可,内部会自动计算变更内容并拼凑动画函数。

2、通过diff算法计算后,可以获得你增删改了哪些数据,然后可以通过 performBatchUpdates 来进行UI的更新,进而替代reloadData方法。好处就是diff后的更新是有针对性的更新,并且自带动画。而reloadData为全量更新,无动画。

3、使用效果

说明 示例 说明 示例
UICollectionView UITableView

4、安装使用

pod 'HDListViewDiffer'

包含类别头文件,调用类别提供的方法即可,详见DEMO

5、全面支持HDCollectionView (当然也支持任意UICollectionView及UITableView)

在HDCollectionView中使用diff时,你仅仅需要指定是否需要动画变更数据即可,接口将更加简单。

顺便放上部分HDCollectionView中的效果

说明 示例 说明 示例
中间对齐删除 瀑布流删除/交换
HDYogaFlowLayout删除/交换 横向滚动diff

其他

理论支持iOS7+ ,个人真机有限,请自行测试

License

HDListViewDiffer is available under the MIT license. See the LICENSE file for more info.

hdlistviewdiffer's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.