Skip to content

fix(helper): restore preloading after clearing adapters - #6827

Open
dajiaohuang wants to merge 1 commit into
CymChad:masterfrom
dajiaohuang:repostew/fix-clear-adapters-preload-20261015
Open

dajiaohuang wants to merge 1 commit into
CymChad:masterfrom
dajiaohuang:repostew/fix-clear-adapters-preload-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown

What and why

clearBeforeAdapters() and clearAfterAdapters() remove their load-more attach listeners from the header/footer adapters, but never put the listeners back on the content adapter. Consequently, clearing the decorations also silently disables leading/trailing preloading.

For example, build a helper with a trailing listener and setTrailPreloadSize(2), add a footer, attach helper.adapter to a RecyclerView, then call clearAfterAdapters(). With trailingLoadState = LoadState.NotLoading(false), scrolling to the final content rows never invokes onLoad(). The leading/header case has the same cause.

Restore the existing listener to the content adapter after each clear, matching the listener ownership used when no headers/footers are present. No API, load-state defaults or dependencies of the shipped library change.

Validation

  • Added two Robolectric API-35 tests with real RecyclerView layout/scrolling and synthetic string rows; both fail on the unchanged production base (expected one load callback, actual zero) and pass with the repair.
  • Tests cover clearing multiple adapters and clearing again, checking that loading resumes once in each direction.
  • ./gradlew :library:compileDebugKotlin test passes (JDK 17; target-pinned RecyclerView 1.4.0 / Kotlin 2.3.21).
  • Separate local smoke fixtures passed for plain/differ list mutations, actual row binding/click/long-click, selected view state, payload updates and empty-state transitions.
  • git diff --check passes.

No physical device, emulator or visual acceptance was performed; the reproduction is an isolated JVM/Robolectric test. No sample-app UI change.

This branch has not been deployed

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

1 participant