Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
5分で学ぶ差分更新とRxDataSources
Search
Yuji Hato
April 10, 2018
Technology
0
270
5分で学ぶ差分更新とRxDataSources
Learn in 5 minutes
Incremental updates and RxDataSources
Yuji Hato
April 10, 2018
Tweet
Share
More Decks by Yuji Hato
See All by Yuji Hato
ABEMAモバイルアプリ開発のDevOps戦略
dekatotoro
1
610
Multiplatform Engineering Roadmap for the Future
dekatotoro
1
130
Introduction to RIBs
dekatotoro
5
1.3k
継続的な開発スタイル 「AbemaTV iOSアプリを週一で リリースしている話」
dekatotoro
6
3.8k
iOS Adaptive UI - 解像度の異なるデバイスや画面の向きに対応する 最適なレイアウトへ -
dekatotoro
0
350
動画アプリをなめらかに動かす技術 - iOS -
dekatotoro
0
320
AbemaTV モバイルアプリの開発体制と 開発プロセスの話
dekatotoro
0
250
Apple TV - tvOS入門 -
dekatotoro
0
120
AbemaTV on Apple TV
dekatotoro
0
38
Other Decks in Technology
See All in Technology
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.4k
2024年にチャレンジしたことを振り返るぞ
mitchan
0
140
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
480
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
5
210
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
190
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
320
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
335
57k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
BBQ
matthewcrist
85
9.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
GraphQLとの向き合い方2022年版
quramy
44
13k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Embracing the Ebb and Flow
colly
84
4.5k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Transcript
AbemaTV iOSࣾϥϯνษڧձ 2018/04/10 Yuji Hato 5ͰֶͿ ࠩߋ৽ͱRxDataSources
About me Yuji Hato CyberAgent, Inc. / AbemaTV, Inc. dekatotoro
@dekatotoro Contributed services
RxDataSources
RxDataSources RxDataSources ͬͯԿʁ
RxDataSources RxSwiftͷͨΊͷUITableViewͱ UICollectionViewͷDataSource
RxDataSources Կ͕خ͍͠ͷʁ
RxDataSources UITableView, UICollectionViewͷ delete, insert, move͕ ؆୯ʹ࣮Ͱ͖Δ !
RxDataSources delete, insert, moveͷͨΊͷߋ৽ͷࠩΛந ग़͢ΔΞϧΰϦζϜਖ਼֬ʹΖ͏ͱ͢Δͱ ͚ͬ͜͏͍͠…
RxDataSources ࠩநग़ΞϧΰϦζϜ
RxDataSources ɾWagner-Fischer ɾHeckel ɾMyers ɾWu …
RxDataSources ࠩநग़ΞϧΰϦζϜͷϥΠϒϥϦ
RxDataSources ɾosteslag/Changeset … Wagner-Fischer ɾjflinter/Dwifft … Myers ɾwokalski/Diff.swift … Myers
ɾonyarnold/Differ … Myers(Diff.swiftͷfork) ɾonmyway133/DeepDiff … HeckelΆ͍ ɾInstagram/IGListKit … Heckel ɾRxSwiftCommunity/RxDataSources … Heckelվ ɾkazuhiro4949/EditDistance … Wu
RxDataSources IGListKit … SectionΛදݱͨ͠ଟ࣍ݩ ྻͷࠩʹରԠ͍ͯ͠ͳ͍ RxDataSources … ϢχʔΫIDΛ࣋ͪɺ ྻʹॏෳ͕ͳ͍લఏͰSectionͷࠩߋ৽
RxDataSources ↓ ͜ΕΘ͔Γ͍͢ https://github.com/horita-yuya/ DifferenceAlgorithmComparison
RxDataSources ࣮
RxDataSources
RxDataSources SectionModelͷprotocol
public protocol SectionModelType { associatedtype Item public var items: [Self.Item]
{ get } public init(original: Self, items: [Self.Item]) } RxDataSources
public protocol IdentifiableType { associatedtype Identity : Hashable public var
identity: Self.Identity { get } } RxDataSources
public protocol AnimatableSectionModelType : SectionModelType, IdentifiableType where Self.Item : IdentifiableType,
Self.Item : Equatable { } RxDataSources
RxDataSources SectionModel
enum DownloadSeriesSectionModel: AnimatableSectionModelType { typealias Item = DownloadSeriesSectionItem case episodeList(season:
DownloadSeason?, items: [Item]) case other(items: [Item]) // Mark: - IdentifiableType var identity: String { … } // Mark: - SectionModelType var items: [DownloadSeriesSectionItem] { switch self { case .episodeList(_, let items): return items case .other(let items): return items } } init(original: DownloadSeriesSectionModel, items: [Item]) { switch original { case .episodeList(let season, _): self = .episodeList(season: season, items: items) case .other: self = .other(items: items) } } } RxDataSources
RxDataSources SectionItemModel
enum DownloadSeriesSectionItem: IdentifiableType, Equatable { case episode(downloadMedia: DownloadMedia) case seeOtherEpisode(series:
DownloadSeries) // Mark: - IdentifiableType var identity: String { … } // Mark: - Equatable static func == (lhs: DownloadSeriesSectionItem, rhs: DownloadSeriesSectionItem) -> Bool { … } } RxDataSources
RxDataSources AnimatableSectionModel
public struct AnimatableSectionModel<Section: IdentifiableType, ItemType: IdentifiableType & Equatable> { public
var model: Section public var items: [Item] public init(model: Section, items: [ItemType]) { self.model = model self.items = items } } extension AnimatableSectionModel : AnimatableSectionModelType { public typealias Item = ItemType public typealias Identity = Section.Identity public var identity: Section.Identity { return model.identity } public init(original: AnimatableSectionModel, items: [Item]) { self.model = original.model self.items = items } public var hashValue: Int { return self.model.identity.hashValue } } RxDataSources Α͘ݟͨΒ3Y%BUB4PVSDFT ʹ"OJNBUBCMF4FDUJPO.PEFM͕ ༻ҙ͞Ε͍ͯΔͷͰ͜ΕΛ͏ ͷ͕CFUUFS
RxDataSources RxTableViewSectionedAnimatedDataSource
open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType> : TableViewSectionedDataSource<S> , RxTableViewDataSourceType { …
public init( animationConfiguration: AnimationConfiguration = AnimationConfiguration(), decideViewTransition: @escaping DecideViewTransition = { _, _, _ in .animated }, configureCell: @escaping ConfigureCell, titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil }, titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil }, canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false }, canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false }, sectionIndexTitles: @escaping SectionIndexTitles = { _ in nil }, sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index } ) { self.animationConfiguration = animationConfiguration self.decideViewTransition = decideViewTransition super.init( configureCell: configureCell, titleForHeaderInSection: titleForHeaderInSection, titleForFooterInSection: titleForFooterInSection, canEditRowAtIndexPath: canEditRowAtIndexPath, canMoveRowAtIndexPath: canMoveRowAtIndexPath, sectionIndexTitles: sectionIndexTitles, sectionForSectionIndexTitle: sectionForSectionIndexTitle ) } … } RxDataSources
final class DownloadSeriesDelegate: NSObject, UITableViewDelegate { … lazy var dataSource:
RxTableViewSectionedAnimatedDataSource<DownloadSeriesSectionModel> = .init( animationConfiguration: AnimationConfiguration(insertAnimation: .fade, reloadAnimation: .none, deleteAnimation: .fade), configureCell: { [weak self] dataSource, table, indexPath, item in guard let me = self else { return UITableViewCell() // Should never reach here. } switch item { case .episode(let downloadMedia): let cell = table.dequeueReusableCell(DownloadListMediaCell.self, forIndexPath: indexPath) cell.configure(downloadMedia: downloadMedia) … return cell case .seeOtherEpisode(let series): let cell = table.dequeueReusableCell(DownloadSeeOtherEpisodeCell.self, forIndexPath: indexPath) cell.rx.tapGesture .subscribe(onNext: { [weak self] in … }) .disposed(by: cell.reusableDisposeBag) … return cell } }) … RxDataSources
final class DownloadSeriesViewStream { … let sectionModels: Property<[DownloadSeriesSectionModel]> private let
_sectionModels = Variable<[DownloadSeriesSectionModel]>([]) … } RxDataSources
final class DownloadSeriesViewController: UIViewController { … viewStream.sectionModels.asObservable() // IMPORTANT: //
crashճආɺཁௐࠪ. .throttle(1.0, latest: true, scheduler: ConcurrentMainScheduler.instance) .bind(to: tableView.rx.items(dataSource: delegate.dataSource)) .disposed(by: rx.disposeBag) … RxDataSources
RxDataSources UITableViewDelegateʁ
// MARK: - UITableViewDelegate func tableView(_ tableView: UITableView, heightForRowAt indexPath:
IndexPath) -> CGFloat { … } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { … } func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { … } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { … } … RxDataSources
Conclusion
Conclusion • ࠩநग़ΞϧΰϦζϜͷϥΠϒϥϦݕ౼͠Α͏ • DiffΞϧΰϦζϜࣗલͰ࡞Ζ͏ͱ͢Δͱ͚ͬ͜͏େม • RxSwift͍ͬͯΔͳΒRxDataSourcesͰྑͦ͞͏
Thank you