Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Fix ]: App Crash when scroll to page 2 in Gallery Screen #956

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

teaim
Copy link

@teaim teaim commented Feb 25, 2024

When the first page is loaded, pageSize=75
https://api.unsplash.com/search/photos?query=Apple&page=1&per_page=75

When the second page is loaded, pageSize=25
https://api.unsplash.com/search/photos?query=Apple&page=2&per_page=25

Duplicate data on the first and second pages

FATAL EXCEPTION: main 
Process: com.google.samples.apps.sunflower, PID: 8802
java.lang.IllegalArgumentException: Key "P2X7NDx_GP0" was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item.

So App Crash when scroll to page 2 in Gallery Screen

Here's my solution, Specify the value of initialLoadSize explicitly

fun getSearchResultStream(query: String): Flow<PagingData<UnsplashPhoto>> {
      return Pager(
          config = PagingConfig(enablePlaceholders = false, pageSize = NETWORK_PAGE_SIZE, initialLoadSize = NETWORK_PAGE_SIZE),
          pagingSourceFactory = { UnsplashPagingSource(service, query) }
      ).flow
  }

@teaim teaim requested a review from a team as a code owner February 25, 2024 16:28
Copy link

google-cla bot commented Feb 25, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant