multiplatform-paging
日付:2022/12/07
URL:https://github.com/cashapp/multiplatform-paging
調査者:mayamito
カテゴリ:KMP(Kotlin Multiplatform)
一言で表すと
AndroidXのPagingをKotlin Multiplatform向けにしたやつ
概要
paging-common
AndroidXのpaging-commonとAPIは同じとのこと(READMEより)。ただしpackage名は違う
なので使い方はAndroidXのほうのPagingのドキュメントを読んでねとのこと
なのでpaging-commonのcommonMainには諸々の型定義が置いてあり、jvmMainを見に行くとAndroidXのPagingの対応するものにtypealiasが貼られている
code:kotlin
package app.cash.paging
actual typealias Pager<Key, Value> = androidx.paging.Pager<Key, Value>
と思いきやJVM以外もAndroidXのPagingをforkしたものにtypealiasが貼られている。力技感がすごい
paging-runtime
AndroidはAndroidXのPagingと互換だからそっち使ってねとのこと。つまりAndroidの実装はこちらでは存在しない。
iOSには、UICollectionViewで扱うためのAPIが用意されている。
code:swift
final class FooViewController: UICollectionViewController {
private let delegate = Paging_runtimePagingCollectionViewController<Foo>(
indexCreator: { row, section in
NSIndexPath(row: Int(truncating: row), section: Int(truncating: section)) as IndexPath
},
)
private let presenter = …
required init(coder: NSCoder) {
super.init(coder: coder)!
presenter.pagingDatas
.sink { pagingData in
self.delegate.submitData(pagingData: pagingData, completionHandler: …)
}
}
override func collectionView(
_ collectionView: UICollectionView,
numberOfItemsInSection section: Int
) -> Int {
return Int(delegate.collectionView(collectionView: collectionView, numberOfItemsInSection: Int64(section)))
}
override func collectionView(
_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FooCell", for: indexPath) as! FooCell
let item = delegate.getItem(position: Int32(indexPath.row))!
// …
return cell
}
}
Mori Atsushi.icon Swift UIじゃないんだ
気になるポイント
メモ
コメント
Go.icon androidxのPagingのインタフェースはAndroidで推奨されるアーキテクチャが反映されていくだろうけど、iOSの推奨アーキテクチャとかとぶつかりそう。