SectionReactor
SectionReactor 是一个用于使用 RxDataSources 管理表格视图和集合视图分区的 ReactorKit 扩展。
入门
这是一个草稿。我不知道如何解释这个概念
ArticleViewSection.swift
enum ArticleViewSection: SectionModelType {
case article(ArticleSectionReactor)
var items: [ArticleViewSection] {
switch self {
case let .article(sectionReactor):
return sectionReactor.currentState.sectionItems
}
}
}
ArticleSectionReactor.swift
import SectionReactor
final class ArticleSectionItem: SectionReactor {
struct State: SectionReactorState {
var sectionItems: [ArticleSectionItem]
}
}
ArticleListViewReactor.swift
final class ArticleListViewReactor: Reactor {
struct State {
var articleSectionReactors: [ArticleSectionReactor]
var sections: [ArticleViewSection] {
return self.articleSectionReactors.map(ArticleViewSection.article)
}
}
func transform(state: Observable<State>) -> Observable<State> {
return state.merge(sections: [
{ $0.articleSectionReactors },
])
}
}
依赖
- ReactorKit >= 0
- RxDataSources >= 2.0
安装
pod 'SectionReactor'
许可协议
SectionReactor处于MIT许可之下。更多信息请见LICENSE。