kuuuurt / multiplatform-paging Goto Github PK
View Code? Open in Web Editor NEWKotlin Multiplatform library for Pagination
License: Apache License 2.0
Kotlin Multiplatform library for Pagination
License: Apache License 2.0
Kotlin 1.4.30 was released a few days ago....not sure if it's binary compatible or not with 1.4.21 but if not be good to get update of this library that supports 1.4.30.
Using combine
with another flow doesn't work. Might be related to kotlinx.coroutines #1764
Are there plans to include support for running on M1 devices (supporting iosSimulatorArm64
target)?
The sample that's in repo has following (for table view)
if (indexPath.row == count - 1) {
viewModel.pager.loadNext()
}
In my SwiftUI iOS client right now I have
if data.shouldDisplayNextPage {
nextPageView
}
....
private var nextPageView: some View {
HStack {
Spacer()
VStack {
ProgressView()
Text("Loading next page...")
}
Spacer()
}
.onAppear(perform: {
data.fetchNextData()
})
}
data
above is view model that calls in to shared KMP code. What I think I'm missing right now is how that shouldDisplayNextPage
can be implemented. For example would it make sense to expose nextKey
from Pager
(or maybe there's already some way to infer this?) Could also perhaps be returned from call to loadNext()
?
If you like I can create PR with this change?
(note above client code is in https://github.com/joreilly/MortyComposeKMM/tree/multiplatform-paging ...updated with 0.3.4 changes)
Should it be possible to use this library with Compose Paging library https://developer.android.com/jetpack/androidx/releases/paging#paging_compose_version_100_2 ?
Hi!
Congratulations for the excellent work!
I think there is a problem with the resetPager function in the iOS implementation and it seams that it's not working.
Looking at the code I see that it sets the _hasNextPage property to false and then calls the loadItems. But as _hasNextPage is false and loadItems checks for _hasNextPage == true it will do nothing. I think _hasNextPage should be reset to true (after all it is true after initialization) but perhaps I am missing something... But as is it doesn't seem to work...
it's written kuuurt while in fact it's kuuuurt!
Hello,
I'm having this problem:
Execution failed for task ':shared:compileKotlinJvm'.
> Could not resolve all files for configuration ':shared:jvmCompileClasspath'.
> Could not resolve io.github.kuuuurt:multiplatform-paging:0.3.9.
Required by:
project :shared
> No matching variant of io.github.kuuuurt:multiplatform-paging:0.3.9 was found. The consumer was configured to find an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
- Variant 'commonMainMetadataElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'debugApiElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9 declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'debugRuntimeElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9 declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'iosArm64ApiElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'iosArm64MetadataElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'iosX64ApiElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'iosX64MetadataElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'metadataApiElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'releaseApiElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9 declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
- Variant 'releaseRuntimeElements-published' capability io.github.kuuuurt:multiplatform-paging:0.3.9 declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Which makes sense because this lib is only available for android()
and ios()
and it works just fine. But now I want to add a server app jvm()
and multiplatformPaging
is a dependency from commonMain
.
I guess this is something this lib should provide, maybe a dummy target for situations like this (don't know if it is possible ๐ )
During my investigation of rickclephas/KMP-NativeCoroutines#10 I noticed the Pager
is updating the PagingData
which fails when the pager is frozen.
Since there is already a StateFlow
I think this could be easily fixed with something like the following:
clientScope.launch {
val newPagingResult = getItems(key, config.pageSize)
hasNextPage = newPagingResult.items.size >= config.pageSize
_pagingData.value = PagingData<V>().apply {
addAll(_pagingData.value)
addAll(newPagingResult.items)
}
currentPagingResult = newPagingResult
}
Hello and thanks for the library.
I need to start with a large empty list and load items into it lazily afterward, in order to set the initial scroll position somewhere in the middle.
I noticed that there is an option for placeholders in the PagingConfig
class:
PagingConfig(
pageSize = 10,
enablePlaceholders = false // Ignored on iOS
)
Is it doing anything currently on Android?
As far as I know, it requires setting the itemsBefore
and itemsAfter
parameters in the androidx.Paging's LoadResult.Page
in order to work.
Hi!
Didn't found this version in Jcenter nor MavenCentral ๐ค
Both Android and iOS have the capability to refresh the pages. However, it isn't clear from common code how to explicitly refresh the list. It would be great to have the ability to trigger a refresh from common code in the repository layer.
Hi there!
Any chance for Kotiln/JS support?
Looking through the codebase, the only iOS-specific code I was able to see in the iosMain
directory are all the platform.darwin.*
imports in DispatcherHelpers
.
Is that accurate?
the present implementation for using map in IOS first casts PagingData into a List and then performs the map operation. later it casts the list back to paging data. the second cast fails throwing an error saying cannot cast ArrayList to Paging data. I am sure map fails but the other PagingData operations also does a double cast meaning they might fail too
Hi @kuuuurt , I'm using the version 4.7 but on Android I can only access pagingData and I can't access loadNext or loadPrevious or any other functions.
cocoapods {
framework {
export("io.github.kuuuurt:multiplatform-paging:0.4.7")
}
}
sourceSets {
val commonMain by getting {
dependencies {
api("io.github.kuuuurt:multiplatform-paging:0.4.7")
}
}
val androidMain by getting {
dependencies {
}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
}
}
}
Any insights ?
Hi,
Thanks for this lib.
Is it possible to make the function List.toPagingData() in PagingData.kt public so we can create empty paging list as in Paging3 (PagingData.empty())
Here is where we can use it for example;
val list by pager.pagingData.collectAsState(
emptyPaging()
)
The current implementation for iOS only works with UiKit for populating a paged list. However, many projects have switched entirely over to SwiftUI for their UI implementation.
It would be nice to have a working SwiftUI example for this library.
kotlin {
...
sourceSets["commonMain"].dependencies {
api("io.github.kuuurt:multiplatform-paging:0.4.2")
}
}
kuuurt is spelled here with 3 "u"s instead of 4. This leads to "Could not resolve dependency" error
AndroidX Paging exposes PagingSource#invalidate
to throw away all currently held state and re-fetch items.
This is going to be extremely easy to implement for JVM (by deferring to AndroidX), but I'm unsure how to go about it for iOS. If you can provide some tips on that front, I'll be more than happy to send a PR.
Need to introduce testing to prevent issues like this
Currently, the way to test it through a manual e2e test. It'd much easier if we can write unit tests for multiplatform-paging
Hello,
I have tried to add the library to the empty projects and everything worked fine. However, when I added the dependency to project which already contains some other libraries I am getting this error:
Unable to build Kotlin project configuration
Unable to build Kotlin project configuration
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find multiplatform-paging-0.3.9-samplessources.jar (io.github.kuuuurt:multiplatform-paging:0.3.9).
After this I can still hardcode the import paths to the project and use the Paging but IDE do not see it and points it as an unresolved refferce (despite the fact that project still compiles).
Any idea how to solve it?
My build.gradle looks like this:
plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("io.gitlab.arturbosch.detekt")
id("maven-publish")
id("com.prof18.kmp.fatframework.cocoa") version "0.0.1"
}
version = "1.0-SNAPSHOT"
repositories {
jcenter()
gradlePluginPortal()
google()
mavenCentral()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}
/**
* Publishing of ios framework
* see this for info how to do it: https://github.com/prof18/kmp-fatframework-cocoa
*
* Publishing of Android framework
* call ./gradlew :kmpcorelib:assemble -> it i will create the aar file in root dir
*/
fatFrameworkCocoaConfig {
fatFrameworkName = "KMPCore"
namePrefix = "KMPCore"
outputPath = "$rootDir/../cocoapods_repo"
versionName = "1.0"
cocoaPodRepoInfo {
summary = "This is a Betsys KMP framework for iOS client"
homepage = "[email protected]:mobile-apps/kmp-ios.git"
license = "Apache"
authors = "\"BetSys\""
gitUrl = "[email protected]:mobile-apps/kmp-ios.git"
}
}
group = "com.betsys.kmpcorelib"
detekt {
autoCorrect = true
config = files("$rootDir/config/detekt.yml")
baseline = file("$rootDir/config/baseline.xml")
input = files("src/commonMain/kotlin")
reports {
html.enabled = true
xml.enabled = true
txt.enabled = true
}
}
val ktorVersion = "1.5.0"
val sqlDelightVersion: String by project
val napierVersion = "1.4.1"
val koinVersion ="3.0.1-beta-2"
kotlin {
android()
// We cant use simple ios() target now, since it doesnt support Arm32 architecture
// For that reason we have specify each target explicitly
// Same for folders with iOS code. We havet to use duplicit iosX64Main etc. instead of one iosMain folder
iosArm32 {
binaries.framework("KMPCore")
}
iosArm64 {
binaries.framework("KMPCore")
}
iosX64 {
binaries.framework("KMPCore")
}
android {
publishLibraryVariants("release", "debug")
publishLibraryVariantsGroupedByFlavor = true
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-mock:$ktorVersion")
implementation("io.insert-koin:koin-core:$koinVersion")
implementation("com.benasher44:uuid:0.2.3")
api("io.github.kuuuurt:multiplatform-paging:0.3.9")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-android:$ktorVersion")
implementation("com.google.android.material:material:1.2.0")
implementation("com.github.aakira:napier:$napierVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.12")
}
}
val iosArm64Main by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation("com.github.aakira:napier:$napierVersion")
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
val iosX64Main by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation("com.github.aakira:napier:$napierVersion")
}
}
val iosArm32Main by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
val iosArm64Test by getting
val iosArm32Test by getting
val iosX64Test by getting
}
}
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(19)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
packagingOptions {
excludes.add("META-INF/*.kotlin_module")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
publishing {
repositories {
maven {
name = "reposilite"
url =
uri("http://maven.betsys.com/${if ((project.version as String).endsWith("-SNAPSHOT")) "snapshots/" else "releases/"}")
credentials {
username = "deployer"
password = "0g3eRmIXPtV5iBnmCPC56MQC8FLZQCVf3df9S+uZ9OCqOd/1z0rLfYpn2SJgcMZd"
}
}
}
}
Hi, are there plans to create version that supports Kotlin 1.5.10 and related dependencies?
Pager appending same pages on top when refresh called in iOS.
According to this line, _pagingData
keep appending next page list to previous list when loadItems called.
then _pagingData
should be invalidated when refresh()
called, but only currentPagingResult
and _hasNextPage
got invalidated.
Library causes crash on Android when trying to refresh.
An instance of PagingSource was re-used when Pager expected to create a new instance. Ensure that the pagingSourceFactory passed to Pager always returns a new instance of PagingSource.
Always create new PagingSource from pagingSourceFactory. See pull request #33.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.