Giter Site home page Giter Site logo

multiplatform-paging's People

Contributors

ilmooo avatar kuuuurt avatar msfjarvis avatar neitex avatar pauldavies83 avatar popalay avatar rickclephas avatar shoheikawano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

multiplatform-paging's Issues

1.4.30 support

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.

IOS not Building on version 0.5.0

When building for ios , theres an error : Could not resolve io.github.kuvurt.multiplatform-paging:multiplatform-paging-jm:0.5.0. which does not arise when using version 0.4.7
Screenshot 2022-12-08 at 10 04 31

Trigger for calling loadNext() on iOS

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)

ios resetPager problem

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...

Could not resolve all files for configuration ':shared:jvmCompileClasspath'

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 ๐Ÿ˜… )

Pager tries to mutate a frozen list on iOS

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
}

Placeholders support

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.

Feature request: Common refresh() call

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.

Javascript support?

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?

Issues in using map on PagingData for IOS

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

Not able to find paging functions in Android

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 ?

Empty PagingData list

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()
    )

Add SwiftUI Support

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.

Mispell in dependency name in readme

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

Allow invalidation of paging data

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.

Paging lib is invisible after adding the dependency to commonMain.

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"
            }
        }
    }
}

Kotlin 1.5 support

Hi, are there plans to create version that supports Kotlin 1.5.10 and related dependencies?

iOS refresh logic is weird

Problem

Pager appending same pages on top when refresh called in iOS.

Inspection

_pagingData.value = _pagingData.value?.toMutableList()?.apply {

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.

Crash on Android when refreshing (version 0.6.x)

Library causes crash on Android when trying to refresh.

Steps to reproduce:

  1. Create pager and collect items in view.
  2. Call 'refresh'-function on Pager or on LazyPagingItems (Compose).
  3. Application crashes.

Crash description:

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.

How to fix:

Always create new PagingSource from pagingSourceFactory. See pull request #33.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.