// // RepositoryReadmeSectionController.swift // Freetime // // Created by Ryan Nystrom on 9/10/17. // Copyright © 2017 Ryan Nystrom. All rights reserved. // import Foundation import IGListKit final class RepositoryReadmeSectionController: ListBindingSectionController, ListBindingSectionControllerDataSource { private lazy var webviewCache: WebviewCellHeightCache = { return WebviewCellHeightCache(sectionController: self) }() private lazy var photoHandler: PhotoViewHandler = { return PhotoViewHandler(viewController: self.viewController) }() override init() { super.init() dataSource = self } // MARK: ListBindingSectionControllerDataSource func sectionController( _ sectionController: ListBindingSectionController, viewModelsFor object: Any ) -> [ListDiffable] { return self.object?.models ?? [] } func sectionController( _ sectionController: ListBindingSectionController, sizeForViewModel viewModel: Any, at index: Int ) -> CGSize { guard let width = collectionContext?.containerSize.width else { fatalError("Missing context") } let height = BodyHeightForComment(viewModel: viewModel, width: width, webviewCache: webviewCache) return CGSize(width: width, height: height) } func sectionController( _ sectionController: ListBindingSectionController, cellForViewModel viewModel: Any, at index: Int ) -> UICollectionViewCell { guard let context = self.collectionContext else { fatalError("Missing context") } let cellClass: AnyClass = CellTypeForComment(viewModel: viewModel) let cell = context.dequeueReusableCell(of: cellClass, for: self, at: index) ExtraCommentCellConfigure( cell: cell, imageDelegate: photoHandler, htmlDelegate: webviewCache, htmlNavigationDelegate: viewController, attributedDelegate: viewController, issueAttributedDelegate: nil ) return cell } }