Skip to content

Trying to use IGListKit with RxSwift🚀

Notifications You must be signed in to change notification settings

SD10/RxIGListKit

Repository files navigation

RxIGListKit

This library wraps IGListAdapter in IGListKit with RxSwift like UICollectionView and UITableView. Trying to use IGListKit with RxSwift and to find a better way to improve it🚀 not ready for production🙅

Example

I implemented Instagram UI with RxSwift and IGListKit in the same way Instagram feed is implemented - detail

To see, clone this repository and run!

|

How to use

Create a dataSource comfirmed to RxIGListAdapterDataSource and IGListAdapterDataSource and use it like UICollectionView and UITableView in RxSwift🎉

lazy privatevar adapter: IGListAdapter = {
    return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 2)
}()

private let disposeBag = DisposeBag()
private let dataSource = DataSource()

override func viewDidLoad() {
    super.viewDidLoad()
    
    adapter.rx.setDataSource(dataSource)
        .disposed(by: disposeBag)

    viewModel.feeds
        .drive(adapter.rx.items(dataSource: dataSource))
        .disposed(by: disposeBag)
}
final class DataSource: NSObject, IGListAdapterDataSource, RxIGListAdapterDataSource {
    typealias Element = [Foo]
    var elements: Element = []

    func listAdapter(_ adapter: IGListAdapter, observedEvent: Event<Element>) {
        if case .next(let elements) = observedEvent {
            self.elements = elements
            adapter.performUpdates(animated: true)
        }
    }

    func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
        return elements
    }

    func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
        return SectionController()
    }

    func emptyView(for listAdapter: IGListAdapter) -> UIView? {
        return nil
    }
}

Help

I am trying to find a good way to wrap up IGListSectionViewController and its delegates. it would be very appriciated to make an issue or PR!

About

Trying to use IGListKit with RxSwift🚀

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages