You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have attempted to reproduce the issue and include an example project.
General information
IGListKit version: 4.0.0
iOS version(s): 16.5
CocoaPods/Carthage version: 1.10.1
Xcode version: 14.3
Devices/Simulators affected: All
Reproducible in the demo project? (Yes/No):
Related issues:
Debug information
I'm running into a ListWorkingRangeDelegate related issue.
Specifically, my list triggers a load behavior when swiped near the bottom, which loads more elements into the list.My implementation is to judge whether it is the last section in sectionControllerWillEnterWorkingRange of ListWorkingRangeDelegate, and trigger the corresponding loading logic.
If I keep sliding the list, the loading logic will be triggered multiple times, resulting in a lot of list elements, such as hundreds of elements.
At this time, the list may be refreshed for some reasons, such as remote notifications or network requests. The number of elements in the list may change from hundreds to dozens.
At this time, if I slide the list arbitrarily, it will frequently trigger the sectionControllerWillEnterWorkingRange callback of ListWorkingRangeDelegate of the last sectionController, and further trigger the loading logic, which is not in line with expectations.
I read the source code of IGListWorkingRangeHandler and I think I find the answer.
IGListWorkingRangeHandler maintains a collection of _visibleSectionIndices, which stores the indices of the current visible sections.
When the willDisplayItemAtIndexPath function is called, IGListWorkingRangeHandler insert the new section into _visibleSectionIndices.
In the _updateWorkingRangesWithListAdapter method, it will traverse the ListWorkingRangeDelegate methods implemented by the corresponding sectionController according to _visibleSectionIndices.
Back to the problem I encountered, if I slide to the middle of the list in a list with 100 elements, then _visibleSectionIndices is assumed to be [80, 81, 82, 83, 84].
If I refresh the list at this point, the list becomes 50 elements, and the visual elements become [40, 41, 42, 43, 44].
But, at this time, the section of _visibleSectionIndices ([80, 81, 82, 83, 84]) will exceed the number of list elements(50).
Let's see how IGListWorkingRangeHandler handles this boundary case.
It can be seen that IGListWorkingRangeHandler cleverly uses the number of objects as the maximum value of end.
Then, although it is still far away from the bottom of the list at this time, the sectionControllerWillEnterWorkingRange method of the last sectionController will be called because of this. So that loading action is started too early before the list reaches the bottom.
The more serious problem is that, the section in _visibleSectionIndices needs to be cleared in the didEndDisplayingItemAtIndexPath method, which will causes sectionControllerWillEnterWorkingRange to be called frequently.
I have temporarily located these information, and did not find that _visibleSectionIndices has any other clearing logic.
I suggest whether _visibleSectionIndices can be cleared when the list is refreshed, or provide an api to clean _visibleSectionIndices.
The text was updated successfully, but these errors were encountered:
New issue checklist
README
and documentationGeneral information
IGListKit
version: 4.0.0Debug information
I'm running into a ListWorkingRangeDelegate related issue.
Specifically, my list triggers a load behavior when swiped near the bottom, which loads more elements into the list.My implementation is to judge whether it is the last section in sectionControllerWillEnterWorkingRange of ListWorkingRangeDelegate, and trigger the corresponding loading logic.
Here is the code sample
If I keep sliding the list, the loading logic will be triggered multiple times, resulting in a lot of list elements, such as hundreds of elements.
At this time, the list may be refreshed for some reasons, such as remote notifications or network requests. The number of elements in the list may change from hundreds to dozens.
At this time, if I slide the list arbitrarily, it will frequently trigger the
sectionControllerWillEnterWorkingRange
callback of ListWorkingRangeDelegate of the last sectionController, and further trigger the loading logic, which is not in line with expectations.I read the source code of IGListWorkingRangeHandler and I think I find the answer.
IGListWorkingRangeHandler maintains a collection of
_visibleSectionIndices
, which stores the indices of the current visible sections.willDisplayItemAtIndexPath
function is called, IGListWorkingRangeHandler insert the new section into_visibleSectionIndices
.didEndDisplayingItemAtIndexPath
is called, IGListWorkingRangeHandler clear the displayed section.In the
_updateWorkingRangesWithListAdapter
method, it will traverse the ListWorkingRangeDelegate methods implemented by the corresponding sectionController according to_visibleSectionIndices
.Back to the problem I encountered, if I slide to the middle of the list in a list with 100 elements, then
_visibleSectionIndices
is assumed to be [80, 81, 82, 83, 84].If I refresh the list at this point, the list becomes 50 elements, and the visual elements become [40, 41, 42, 43, 44].
But, at this time, the section of _visibleSectionIndices ([80, 81, 82, 83, 84]) will exceed the number of list elements(50).
Let's see how IGListWorkingRangeHandler handles this boundary case.
It can be seen that IGListWorkingRangeHandler cleverly uses the number of objects as the maximum value of end.
Then, although it is still far away from the bottom of the list at this time, the
sectionControllerWillEnterWorkingRange
method of the last sectionController will be called because of this. So that loading action is started too early before the list reaches the bottom.The more serious problem is that, the section in _visibleSectionIndices needs to be cleared in the
didEndDisplayingItemAtIndexPath
method, which will causessectionControllerWillEnterWorkingRange
to be called frequently.I have temporarily located these information, and did not find that
_visibleSectionIndices
has any other clearing logic.I suggest whether
_visibleSectionIndices
can be cleared when the list is refreshed, or provide an api to clean_visibleSectionIndices
.The text was updated successfully, but these errors were encountered: