Closed hsuyelin closed 6 years ago
let examples: [(String, UIViewController.Type)] = [ ("Horizontal Gallery", HorizontalGalleryViewController.self), ("Grid", GridViewController.self), ("Articles", ArticleExampleViewController.self), ("Reload", ReloadDataViewController.self), ("Reload Animation", ReloadAnimationViewController.self), ("Header", HeaderExampleViewController.self), ("Chat", MessagesViewController.self), ("Animators", AnimatorExampleViewController.self) ] override func viewDidLoad() { super.viewDidLoad() let examplesSection = BasicProvider( dataSource: ArrayDataSource(data: examples), viewSource: ClosureViewSource(viewUpdater: { (view: ExampleView, data: (String, UIViewController.Type), at: Int) in view.populate(title: data.0, contentViewControllerType: data.1) }), sizeSource: { (index, data, size) -> CGSize in // I want to control the height of each item here. If the data changes, it will change here by collectionView reloadData. }, layout: FlowLayout(lineSpacing: 30).inset(by: bodyInset) ) provider = ComposedProvider(sections: [ space(100), LabelProvider(text: "CollectionKit", font: .boldSystemFont(ofSize: 38), insets: headerInset), LabelProvider(text: "A modern swift framework for building reusable collection view components.", font: .systemFont(ofSize: 20), insets: bodyInset), space(30), LabelProvider(text: "Examples", font: .boldSystemFont(ofSize: 30), insets: headerInset), examplesSection, space(30) ]) }
Not sure what your question meant. Why not just return your calculated size for each data? you can store some more attributes inside the examples array. maybe use a enum indicating how its size is calculated.
examples